func (h *Handler) UpdatePassword(c echo.Context) (err error) {
	userID := userIDFromToken(c)
	newPassword := c.FormValue("newPassword")
	oldPassword := c.FormValue("oldPassword")

	user := model.User{}
	db := h.DB.Clone()

	if err = db.DB(config.DbName).C("users").FindId(bson.ObjectIdHex(userID)).One(&user); err != nil {
		return
	}
	defer db.Close()

	if !logic.ComparePasswords(user.Password, oldPassword) {
		return &echo.HTTPError{Code: http.StatusUnauthorized, Message: "wrong old password"}
	}

	if !logic.IsValidPassword(newPassword) {
		return &echo.HTTPError{Code: http.StatusUnauthorized, Message: "invalid new password"}
	}

	if err = db.DB(config.DbName).C("users").
		UpdateId(bson.ObjectIdHex(userID), bson.M{"$set": bson.M{"password": logic.HashPassword(newPassword)}}); err != nil {
		if err == mgo.ErrNotFound {
			return echo.ErrNotFound
		}
	}

	return
}
// UpdatePassword to update profile of the user
UpdatePassword to update profile of the user
// UpdatePassword to update profile of the user
func (h *Handler) UpdatePassword(c echo.Context) (err error) {
	userID := userIDFromToken(c)
	newPassword := c.FormValue("newPassword")
	oldPassword := c.FormValue("oldPassword")
	user := model.User{}
	db := h.DB.Clone()
	if err = db.DB(config.DbName).C("users").FindId(bson.ObjectIdHex(userID)).One(&user); err != nil {
		return
	}
	defer db.Close()
	if !logic.ComparePasswords(user.Password, oldPassword) {
		return &echo.HTTPError{Code: http.StatusUnauthorized, Message: "wrong old password"}
	}
	if !logic.IsValidPassword(newPassword) {
		return &echo.HTTPError{Code: http.StatusUnauthorized, Message: "invalid new password"}
	}
	if err = db.DB(config.DbName).C("users").
		UpdateId(bson.ObjectIdHex(userID), bson.M{"$set": bson.M{"password": logic.HashPassword(newPassword)}}); err != nil {
		if err == mgo.ErrNotFound {
			return echo.ErrNotFound
		}
	}
	return
}
func ( h * Handler ) UpdatePassword ( c echo . Context ) ( err error ) { userID := userIDFromToken ( c ) newPassword := c . FormValue ( " " ) oldPassword := c . FormValue ( " " ) user := model . User { } db := h . DB . Clone ( ) if err = db . DB ( config . DbName ) . C ( " " ) . FindId ( bson . ObjectIdHex ( userID ) ) . One ( & user ) ; err != nil { return } defer db . Close ( ) if ! logic . ComparePasswords ( user . Password , oldPassword ) { return & echo . HTTPError { Code : http . StatusUnauthorized , Message : " " } } if ! logic . IsValidPassword ( newPassword ) { return & echo . HTTPError { Code : http . StatusUnauthorized , Message : " " } } if err = db . DB ( config . DbName ) . C ( " " ) . UpdateId ( bson . ObjectIdHex ( userID ) , bson . M { " " : bson . M { " " : logic . HashPassword ( newPassword ) } } ) ; err != nil { if err == mgo . ErrNotFound { return echo . ErrNotFound } } return }
UpdatePassword to update profile of the user
UpdatePassword to update profile of the user