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

Function EditUserPost

internal/route/admin/users.go:158–217  ·  view source on GitHub ↗
(c *context.Context, f form.AdminEditUser)

Source from the content-addressed store, hash-verified

156}
157
158func EditUserPost(c *context.Context, f form.AdminEditUser) {
159 c.Data["Title"] = c.Tr("admin.users.edit_account")
160 c.Data["PageIsAdmin"] = true
161 c.Data["PageIsAdminUsers"] = true
162 c.Data["EnableLocalPathMigration"] = conf.Repository.EnableLocalPathMigration
163
164 u := prepareUserInfo(c)
165 if c.Written() {
166 return
167 }
168
169 if c.HasError() {
170 c.HTML(http.StatusBadRequest, tmplAdminUserEdit)
171 return
172 }
173
174 opts := database.UpdateUserOptions{
175 LoginName: &f.LoginName,
176 FullName: &f.FullName,
177 Website: &f.Website,
178 Location: &f.Location,
179 MaxRepoCreation: &f.MaxRepoCreation,
180 IsActivated: &f.Active,
181 IsAdmin: &f.Admin,
182 AllowGitHook: &f.AllowGitHook,
183 AllowImportLocal: &f.AllowImportLocal,
184 ProhibitLogin: &f.ProhibitLogin,
185 }
186
187 fields := strings.Split(f.LoginType, "-")
188 if len(fields) == 2 {
189 loginSource, _ := strconv.ParseInt(fields[1], 10, 64)
190 if u.LoginSource != loginSource {
191 opts.LoginSource = &loginSource
192 }
193 }
194
195 if f.Password != "" {
196 opts.Password = &f.Password
197 }
198
199 if u.Email != f.Email {
200 opts.Email = &f.Email
201 }
202
203 err := database.Handle.Users().Update(c.Req.Context(), u.ID, opts)
204 if err != nil {
205 if database.IsErrEmailAlreadyUsed(err) {
206 c.Data["Err_Email"] = true
207 c.RenderWithErr(c.Tr("form.email_been_used"), http.StatusUnprocessableEntity, tmplAdminUserEdit, &f)
208 } else {
209 c.Error(err, "update user")
210 }
211 return
212 }
213 log.Trace("Account updated by admin %q: %s", c.User.Name, u.Name)
214
215 c.Flash.Success(c.Tr("admin.users.update_profile_success"))

Callers

nothing calls this directly

Calls 12

IsErrEmailAlreadyUsedFunction · 0.92
prepareUserInfoFunction · 0.85
TrMethod · 0.80
HasErrorMethod · 0.80
HTMLMethod · 0.80
SplitMethod · 0.80
UsersMethod · 0.80
RenderWithErrMethod · 0.80
SuccessMethod · 0.80
RedirectMethod · 0.80
UpdateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected