Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LocalHandler = func(c echo.Context) error { p := new(localParams) if err := c.Bind(p); err != nil { return c.JSON(http.StatusBadRequest, err) } if err := common.Validate(p); err != nil { return c.JSON(http.StatusBadRequest, err) } users, err := models.Users(qm.Where("email = ?", p.Email)).AllG() if err != nil { return c.JSON(http.StatusInternalServerError, fmt.Sprintln(err)) } if users == nil { return c.JSON(http.StatusUnauthorized, "Invalid credentials") } user := users[0] if user.Password.Ptr() == nil { return c.JSON(http.StatusUnauthorized, "Password not defined") } if ok := services.VerifyUserPassword(user, p.Password); !ok { return c.JSON(http.StatusUnauthorized, "Invalid credentials") } if user.Role == models.UserRoleDisable { return c.JSON(http.StatusUnauthorized, "Account disabled") } _, err = SetToken(c, user) if err != nil { return c.JSON(http.StatusInternalServerError, fmt.Sprintln(err)) } return c.JSON(http.StatusOK, &respJSON{ ID: user.ID, Email: user.Email, DisplayName: user.DisplayName, Picture: user.Picture, Role: user.Role, }) }
LocalHandler auth local
View Source
var LogoutHandler = func(c echo.Context) error { RemoveToken(c) return c.JSON(http.StatusOK, "ok") }
LogoutHandler auth logout
View Source
var RegisterHandler = func(c echo.Context) error { p := new(registerParams) if err := c.Bind(p); err != nil { return c.JSON(http.StatusBadRequest, err) } if err := common.Validate(p); err != nil { return c.JSON(http.StatusBadRequest, err) } users, err := models.Users(qm.Where("email = ?", p.Email)).AllG() if err != nil { return c.JSON(http.StatusInternalServerError, err) } if users != nil { return c.JSON(http.StatusBadRequest, "Email already exists") } user := &models.User{ Email: p.Email, } if err := services.SetUserPassword(user, p.Password); err != nil { return c.JSON(http.StatusInternalServerError, err) } err = user.InsertG(boil.Whitelist("email", "password", "token_version")) if err != nil { return c.JSON(http.StatusInternalServerError, err) } _, err = SetToken(c, user) if err != nil { return c.JSON(http.StatusInternalServerError, err) } return c.JSON(http.StatusOK, &respJSON{ ID: user.ID, Email: user.Email, DisplayName: user.DisplayName, Picture: user.Picture, Role: user.Role, }) }
RegisterHandler auth local
Functions ¶
func OAuth2CallbackHandler ¶
OAuth2CallbackHandler oauth2 callback
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.