mirror of https://github.com/gogits/gogs.git
Unknown
11 years ago
9 changed files with 204 additions and 15 deletions
@ -0,0 +1,63 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin |
||||
|
||||
import ( |
||||
"strings" |
||||
|
||||
"github.com/gogits/gogs/models" |
||||
"github.com/gogits/gogs/modules/auth" |
||||
"github.com/gogits/gogs/modules/log" |
||||
"github.com/gogits/gogs/modules/middleware" |
||||
) |
||||
|
||||
func NewUser(ctx *middleware.Context, form auth.RegisterForm) { |
||||
ctx.Data["Title"] = "New Account" |
||||
|
||||
if ctx.Req.Method == "GET" { |
||||
ctx.HTML(200, "admin/users/new") |
||||
return |
||||
} |
||||
|
||||
if form.Password != form.RetypePasswd { |
||||
ctx.Data["HasError"] = true |
||||
ctx.Data["Err_Password"] = true |
||||
ctx.Data["Err_RetypePasswd"] = true |
||||
ctx.Data["ErrorMsg"] = "Password and re-type password are not same" |
||||
auth.AssignForm(form, ctx.Data) |
||||
} |
||||
|
||||
if ctx.HasError() { |
||||
ctx.HTML(200, "admin/users/new") |
||||
return |
||||
} |
||||
|
||||
u := &models.User{ |
||||
Name: form.UserName, |
||||
Email: form.Email, |
||||
Passwd: form.Password, |
||||
IsActive: true, |
||||
} |
||||
|
||||
var err error |
||||
if u, err = models.RegisterUser(u); err != nil { |
||||
switch err { |
||||
case models.ErrUserAlreadyExist: |
||||
ctx.RenderWithErr("Username has been already taken", "admin/users/new", &form) |
||||
case models.ErrEmailAlreadyUsed: |
||||
ctx.RenderWithErr("E-mail address has been already used", "admin/users/new", &form) |
||||
case models.ErrUserNameIllegal: |
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form) |
||||
default: |
||||
ctx.Handle(200, "admin.user.NewUser", err) |
||||
} |
||||
return |
||||
} |
||||
|
||||
log.Trace("%s User created by admin(%s): %s", ctx.Req.RequestURI, |
||||
ctx.User.LowerName, strings.ToLower(form.UserName)) |
||||
|
||||
ctx.Redirect("/admin/users") |
||||
} |
@ -0,0 +1,54 @@
|
||||
{{template "base/head" .}} |
||||
{{template "base/navbar" .}} |
||||
<div id="gogs-body" class="container" data-page="admin"> |
||||
{{template "admin/nav" .}} |
||||
<div id="gogs-admin-container" class="col-md-9"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-heading"> |
||||
New Account |
||||
</div> |
||||
|
||||
<div class="panel-body"> |
||||
<br/> |
||||
<form action="/admin/users/new" method="post" class="form-horizontal"> |
||||
<div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div> |
||||
<div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}"> |
||||
<label class="col-md-4 control-label">Username: </label> |
||||
<div class="col-md-6"> |
||||
<input name="username" class="form-control" placeholder="Type account's username" value="{{.username}}" required="required"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group {{if .Err_Email}}has-error has-feedback{{end}}"> |
||||
<label class="col-md-4 control-label">Email: </label> |
||||
<div class="col-md-6"> |
||||
<input name="email" class="form-control" placeholder="Type account's e-mail address" value="{{.email}}" required="required" title="Email is not valid"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group {{if .Err_Password}}has-error has-feedback{{end}}"> |
||||
<label class="col-md-4 control-label">Password: </label> |
||||
<div class="col-md-6"> |
||||
<input name="passwd" type="password" class="form-control" placeholder="Type account's password" required="required" title="Password must contain at least 6 characters"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group {{if .Err_RetypePasswd}}has-error has-feedback{{end}}"> |
||||
<label class="col-md-4 control-label">Re-type: </label> |
||||
<div class="col-md-6"> |
||||
<input name="retypepasswd" type="password" class="form-control" placeholder="Re-type account's password" required="required" title="Re-type Password must be same to Password"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group"> |
||||
<div class="col-md-offset-4 col-md-6"> |
||||
<button type="submit" class="btn btn-lg btn-primary">Create new account</button> |
||||
</div> |
||||
</div> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
|
||||
</div> |
||||
</div> |
||||
{{template "base/footer" .}} |
Loading…
Reference in new issue