@ -16,14 +16,15 @@ import (
"github.com/gogits/gogs/modules/middleware"
)
func NewUser ( ctx * middleware . Context , form auth . RegisterForm ) {
func NewUser ( ctx * middleware . Context ) {
ctx . Data [ "Title" ] = "New Account"
ctx . Data [ "PageIsUsers" ] = true
ctx . HTML ( 200 , "admin/users/new" )
}
if ctx . Req . Method == "GET" {
ctx . HTML ( 200 , "admin/users/new" )
return
}
func NewUserPost ( ctx * middleware . Context , form auth . RegisterForm ) {
ctx . Data [ "Title" ] = "New Account"
ctx . Data [ "PageIsUsers" ] = true
if form . Password != form . RetypePasswd {
ctx . Data [ "HasError" ] = true
@ -55,7 +56,7 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
case models . ErrUserNameIllegal :
ctx . RenderWithErr ( models . ErrRepoNameIllegal . Error ( ) , "admin/users/new" , & form )
default :
ctx . Handle ( 2 00, "admin.user.NewUser" , err )
ctx . Handle ( 5 00, "admin.user.NewUser" , err )
}
return
}
@ -66,25 +67,39 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
ctx . Redirect ( "/admin/users" )
}
func EditUser ( ctx * middleware . Context , params martini . Params , form auth . AdminEditUserForm ) {
func EditUser ( ctx * middleware . Context , params martini . Params ) {
ctx . Data [ "Title" ] = "Edit Account"
ctx . Data [ "PageIsUsers" ] = true
uid , err := base . StrTo ( params [ "userid" ] ) . Int ( )
if err != nil {
ctx . Handle ( 200 , "admin.user.EditUser" , err )
ctx . Handle ( 404 , "admin.user.EditUser" , err )
return
}
u , err := models . GetUserById ( int64 ( uid ) )
if err != nil {
ctx . Handle ( 2 00, "admin.user.EditUser" , err )
ctx . Handle ( 5 00, "admin.user.EditUser" , err )
return
}
if ctx . Req . Method == "GET" {
ctx . Data [ "User" ] = u
ctx . HTML ( 200 , "admin/users/edit" )
ctx . Data [ "User" ] = u
ctx . HTML ( 200 , "admin/users/edit" )
}
func EditUserPost ( ctx * middleware . Context , params martini . Params , form auth . AdminEditUserForm ) {
ctx . Data [ "Title" ] = "Edit Account"
ctx . Data [ "PageIsUsers" ] = true
uid , err := base . StrTo ( params [ "userid" ] ) . Int ( )
if err != nil {
ctx . Handle ( 404 , "admin.user.EditUser" , err )
return
}
u , err := models . GetUserById ( int64 ( uid ) )
if err != nil {
ctx . Handle ( 500 , "admin.user.EditUser" , err )
return
}
@ -96,47 +111,44 @@ func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEdi
u . IsActive = form . Active == "on"
u . IsAdmin = form . Admin == "on"
if err := models . UpdateUser ( u ) ; err != nil {
ctx . Handle ( 2 00, "admin.user.EditUser" , err )
ctx . Handle ( 5 00, "admin.user.EditUser" , err )
return
}
ctx . Data [ "IsSuccess" ] = true
ctx . Data [ "User" ] = u
ctx . HTML ( 200 , "admin/users/edit" )
log . Trace ( "%s User profile updated by admin(%s): %s" , ctx . Req . RequestURI ,
ctx . User . LowerName , ctx . User . LowerName )
ctx . Data [ "User" ] = u
ctx . Flash . Success ( "Account profile has been successfully updated." )
ctx . Redirect ( "/admin/users/" + params [ "userid" ] )
}
func DeleteUser ( ctx * middleware . Context , params martini . Params ) {
ctx . Data [ "Title" ] = "Edit Account"
ctx . Data [ "Title" ] = "Delete Account"
ctx . Data [ "PageIsUsers" ] = true
log . Info ( "delete" )
uid , err := base . StrTo ( params [ "userid" ] ) . Int ( )
if err != nil {
ctx . Handle ( 200 , "admin.user.EditUser" , err )
ctx . Handle ( 404 , "admin.user.EditUser" , err )
return
}
u , err := models . GetUserById ( int64 ( uid ) )
if err != nil {
ctx . Handle ( 2 00, "admin.user.EditUser" , err )
ctx . Handle ( 5 00, "admin.user.EditUser" , err )
return
}
if err = models . DeleteUser ( u ) ; err != nil {
ctx . Data [ "HasError" ] = true
switch err {
case models . ErrUserOwnRepos :
ctx . Data [ "ErrorMsg" ] = "This account still has ownership of repository, owner has to delete or transfer them first."
ctx . Data [ "User" ] = u
ctx . HTML ( 200 , "admin/users/edit" )
ctx . Flash . Error ( "This account still has ownership of repository, owner has to delete or transfer them first." )
ctx . Redirect ( "/admin/users/" + params [ "userid" ] )
default :
ctx . Handle ( 2 00, "admin.user.DeleteUser" , err )
ctx . Handle ( 5 00, "admin.user.DeleteUser" , err )
}
return
}
log . Trace ( "%s User deleted by admin(%s): %s" , ctx . Req . RequestURI ,
ctx . User . LowerName , ctx . User . LowerName )