2018-04-17 09:16:03 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
2018-04-17 10:04:36 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"git.trj.tw/golang/go-gallery/models"
|
2018-04-17 09:16:03 +00:00
|
|
|
"git.trj.tw/golang/go-gallery/modules/context"
|
2018-04-17 10:04:36 +00:00
|
|
|
"git.trj.tw/golang/go-gallery/modules/utils"
|
2018-04-17 09:16:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UserLogin route
|
|
|
|
func UserLogin(c *context.Context) {
|
|
|
|
loginArg := struct {
|
|
|
|
Account string `form:"account" json:"account" binding:"required"`
|
|
|
|
Password string `form:"password" json:"password" binding:"required"`
|
|
|
|
}{
|
|
|
|
Account: "",
|
|
|
|
Password: "",
|
|
|
|
}
|
|
|
|
err := c.ShouldBind(&loginArg)
|
|
|
|
if err != nil {
|
2018-04-17 10:04:36 +00:00
|
|
|
c.DataFormat(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
acc, err := models.GetAccount(loginArg.Account)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
c.ServerError(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if acc == nil {
|
|
|
|
c.NotFound("User not found")
|
2018-04-17 09:16:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-17 10:04:36 +00:00
|
|
|
c.Success(utils.ToMap(acc))
|
2018-04-17 09:16:03 +00:00
|
|
|
}
|