34 lines
886 B
Go
34 lines
886 B
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
"ExpiryDatesManager/server/model"
|
|
"ExpiryDatesManager/server/utils"
|
|
"encoding/json"
|
|
)
|
|
|
|
var CreateAccount = func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
account := &model.Account{}
|
|
err := json.NewDecoder(r.Body).Decode(account) //decode the request body into struct and failed if any error occur
|
|
if err != nil {
|
|
utils.Respond(w, utils.Message(false, "Invalid request"))
|
|
return
|
|
}
|
|
|
|
resp := account.Create() //Create account
|
|
utils.Respond(w, resp)
|
|
}
|
|
|
|
var Authenticate = func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
account := &model.Account{}
|
|
err := json.NewDecoder(r.Body).Decode(account) //decode the request body into struct and failed if any error occur
|
|
if err != nil {
|
|
utils.Respond(w, utils.Message(false, "Invalid request"))
|
|
return
|
|
}
|
|
|
|
resp := model.Login(account.Email, account.Password)
|
|
utils.Respond(w, resp)
|
|
} |