func DeleteUser(user models.User) { _, err := r.Db("harbor").Table("users").Get(user.Id).Delete().Run(service.Session()) if err != nil { fmt.Println(err) return } }
func CreateTestUser() (models.User, error) { user := models.User{ Username: "******", Fullname: "Jefferson Carley", PasswordHash: "0b2f219acb4b0cd9c5181f77ed41484fc286d0c11878005be2d4e7695255e2dc", PasswordSalt: "d61162e555f68c3151133351fc908d688aa2bb1e5bab958859290c443eeec0bc", IsDisabled: false, } user.Created = time.Now() res, err := r.Db("harbor").Table("users").Insert(user).RunWrite(service.Session()) if err != nil { return models.User{}, err } user.Id = res.GeneratedKeys[0] return user, nil }
func signIn(ctx context, w http.ResponseWriter, req *http.Request) { email := req.PostFormValue("inputEmail") password := req.PostFormValue("inputPassword") res, err := r.Db("harbor").Table("users").Filter(r.Row.Field("username").Eq(email)).Run(service.Session()) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } defer res.Close() user := models.User{} err = res.One(&user) if err != nil { fmt.Println(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } password_hash := user.PasswordHash salt := user.PasswordSalt dk, _ := scrypt.Key([]byte(password), []byte(salt), 16384, 8, 1, 32) fmt.Printf("%s\n", password_hash) fmt.Printf("%x\n", dk) if password_hash == fmt.Sprintf("%x", dk) { user_session := models.NewUserSession(user) session, _ := ctx.SessionStore().Get(req, "login") session.Values["username"] = user.Username session.Values["sessionKey"] = user_session.SessionKey session.Save(req, w) w.Write([]byte("success")) } else { http.Redirect(w, req, "index.html", 301) } }