github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RDeleteUser.go (about)

     1  package root
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/insionng/makross"
     7  
     8  	"strconv"
     9  	"strings"
    10  	"time"
    11  
    12  	"github.com/insionng/yougam/models"
    13  )
    14  
    15  func GetRDeleteUserHandler(self *makross.Context) error {
    16  
    17  	_usr_, okay := self.Session.Get("SignedUser").(*models.User)
    18  	if !okay {
    19  		return self.NoContent(401)
    20  	}
    21  
    22  	opuid := _usr_.Id
    23  	if userid := self.Param("uid").MustInt64(); userid > 0 {
    24  		if e := models.DelUser(userid, opuid, _usr_.Role); e != nil {
    25  			self.Flash.Error("删除 User id:"+strconv.FormatInt(userid, 10)+"出现错误 "+fmt.Sprintf("%s", e)+"!", false)
    26  			return self.Redirect("/root/read/user/")
    27  		} else {
    28  
    29  			self.Flash.Success("删除 User id:"+strconv.FormatInt(userid, 10)+"成功!", false)
    30  			if strings.HasPrefix(self.RequestURI(), "/root/delete/administrator/") {
    31  				return self.Redirect("/root/read/administrator/")
    32  			} else {
    33  				return self.Redirect("/root/read/user/")
    34  			}
    35  
    36  		}
    37  	}
    38  
    39  	return self.Redirect("/root/read/user/?version=" + strconv.Itoa(int(time.Now().Unix())))
    40  
    41  }