コード例 #1
0
ファイル: UserController.go プロジェクト: Klouds/klouds
//profile page
func (c *UserController) Profile(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
	if r.Method == "GET" {
		RedirectToLogin(c, rw, r, p)

	} else if r.Method == "POST" {
		// if logged in, go to profile / else login page
		var user *models.User

		if getUserName(r) != "" {
			user = GetUserByUsername(getUserName(r))

		} else {
			c.HTML(rw, http.StatusOK, "user/login", nil)
			return
		}

		r.ParseForm()

		currentPassword := r.FormValue("currentpassword")
		password := r.FormValue("password")
		confirmpassword := r.FormValue("confirmpassword")

		user.Password = currentPassword

		//Check to make sure password matches record
		if CheckForMatchingPassword(user) {
			//Passwords Match
			//Validate new password, make sure they match, update user,display success message

			user.Password = password
			user.ConfirmPassword = confirmpassword

			user.ValidateNewPassword()

			if user.Message != "" {
				c.HTML(rw, http.StatusOK, "user/profile", user)
				return
			} else {
				user.Message = "Updated user"
				UpdateUser(user)
				c.HTML(rw, http.StatusOK, "user/profile", user)
				return
			}

		} else {
			user.Message = "Password doesn't match record for " + user.Username
		}

		c.HTML(rw, http.StatusOK, "user/profile", user)
	}
}