Пример #1
0
func (ctx *LoginController) Login() {

	if ctx.Ctx.Input.Method() == "POST" {
		login := models.User{}

		if err := ctx.ParseForm(&login); err != nil {
			error := map[string]string{"status": "ERROR", "errorMsg": "An error occured"}
			ctx.Data["json"] = &error
			ctx.ServeJson()
		} else {
			error := login.GetOne("Email")
			if error == nil {
				if login.Password != security.Sha512(ctx.GetString("password")) {
					error := map[string]string{"status": "ERROR", "errorMsg": "Invalid username or password"}
					ctx.Data["json"] = &error
					ctx.ServeJson()
				} else {
					success := map[string]string{"status": "SUCCESS", "email": login.Email, "userid": strconv.FormatInt(login.Id, 10), "name": login.Name}
					ctx.Data["json"] = &success
					ctx.ServeJson()
				}
			} else {
				error := map[string]string{"status": "ERROR", "errorMsg": "Invalid username or password"}
				ctx.Data["json"] = &error
				ctx.ServeJson()
			}
		}
	}
}
Пример #2
0
func (ctx *SignupController) Signup() {
	if ctx.Ctx.Input.Method() == "POST" {
		s := models.User{}

		err := ctx.ParseForm(&s)
		if err != nil {
			error := map[string]string{"status": "ERROR", "errorMsg": "An error occured"}
			ctx.Data["json"] = &error
			ctx.ServeJson()
		} else {
			_, insertErr := s.Save()
			if insertErr == nil {
				success := map[string]string{"status": "SUCCESS"}
				ctx.Data["json"] = &success
				ctx.ServeJson()
			} else {
				error := map[string]string{"status": "ERROR", "errorMsg": "An error occured"}
				ctx.Data["json"] = &error
				ctx.ServeJson()
			}
		}
	}
}