(c *context.Context, f form.AdminEditUser)
| 156 | } |
| 157 | |
| 158 | func 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")) |
nothing calls this directly
no test coverage detected