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

     1  package root
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/insionng/makross"
     6  	
     7  	"github.com/insionng/yougam/models"
     8  )
     9  
    10  func GetRSettingPasswordHandler(self *makross.Context) error {
    11  	self.Set("catpage", "RSettingPasswordHandler")
    12  	TplNames := "root/setting_password"
    13  	return self.Render(TplNames)
    14  }
    15  
    16  func PostRSettingPasswordHandler(self *makross.Context) error {
    17  
    18  	
    19  	_usr_, okay := self.Session.Get("SignedUser").(*models.User)
    20  	if !okay {
    21  		return self.NoContent(401)
    22  	}
    23  
    24  	email := self.FormValue("email")
    25  	oldpassword := self.FormValue("oldpassword")
    26  	newpassword := self.FormValue("newpassword")
    27  	username := _usr_.Username
    28  
    29  	if len(username) == 0 {
    30  		self.Flash.Error("请填写管理员用户名,不能为空!")
    31  		return self.Redirect("/root/setting/password/")
    32  
    33  	}
    34  
    35  	if len(email) == 0 {
    36  		self.Flash.Error("请填写管理员注册邮箱,以便系统验证,不能为空!")
    37  		return self.Redirect("/root/setting/password/")
    38  
    39  	}
    40  
    41  	if len(oldpassword) == 0 {
    42  		self.Flash.Error("请填写管理员当前密码,以便系统验证你的身份,不能为空!")
    43  		return self.Redirect("/root/setting/password/")
    44  
    45  	}
    46  
    47  	if len(newpassword) == 0 {
    48  		self.Flash.Error("请填写管理员新密码,不能为空!")
    49  		return self.Redirect("/root/setting/password/")
    50  
    51  	}
    52  
    53  	if len(username) > 0 && len(email) > 0 && len(oldpassword) > 0 && len(newpassword) > 0 {
    54  
    55  		if t, e := models.SetUserNewpassword(username, email, oldpassword, newpassword); t {
    56  			self.Flash.Success(fmt.Sprint("设置新密码成功", e))
    57  		} else {
    58  			self.Flash.Error(fmt.Sprint("设置新密码失败", e))
    59  		}
    60  
    61  		return self.Redirect("/root/setting/password/")
    62  
    63  	} else {
    64  		self.Flash.Error("请完整填写所有项目,不能为空!")
    65  		return self.Redirect("/root/setting/password/")
    66  
    67  	}
    68  
    69  }