MCPcopy Create free account
hub / github.com/gogs/gogs / SettingsPasswordPost

Function SettingsPasswordPost

internal/route/user/setting.go:198–227  ·  view source on GitHub ↗
(c *context.Context, f form.ChangePassword)

Source from the content-addressed store, hash-verified

196}
197
198func SettingsPasswordPost(c *context.Context, f form.ChangePassword) {
199 c.Title("settings.password")
200 c.PageIs("SettingsPassword")
201
202 if c.HasError() {
203 c.HTML(http.StatusBadRequest, tmplUserSettingsPassword)
204 return
205 }
206
207 if !userutil.ValidatePassword(c.User.Password, c.User.Salt, f.OldPassword) {
208 c.Flash.Error(c.Tr("settings.password_incorrect"))
209 } else if f.Password != f.Retype {
210 c.Flash.Error(c.Tr("form.password_not_match"))
211 } else {
212 err := database.Handle.Users().Update(
213 c.Req.Context(),
214 c.User.ID,
215 database.UpdateUserOptions{
216 Password: &f.Password,
217 },
218 )
219 if err != nil {
220 c.Errorf(err, "update user")
221 return
222 }
223 c.Flash.Success(c.Tr("settings.change_password_success"))
224 }
225
226 c.RedirectSubpath("/user/settings/password")
227}
228
229func SettingsEmails(c *context.Context) {
230 c.Title("settings.emails")

Callers

nothing calls this directly

Calls 12

ValidatePasswordFunction · 0.92
TitleMethod · 0.80
PageIsMethod · 0.80
HasErrorMethod · 0.80
HTMLMethod · 0.80
TrMethod · 0.80
UsersMethod · 0.80
SuccessMethod · 0.80
RedirectSubpathMethod · 0.80
UpdateMethod · 0.65
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected