Add the possibility to change JID of user.
This commit is contained in:
parent
716835d67b
commit
7113e69a91
|
|
@ -24,20 +24,37 @@ func (c *UserController) Prepare() {
|
|||
}
|
||||
|
||||
func (c *UserController) Get() {
|
||||
loginStr := c.getUserLogin()
|
||||
u := user.GetUserByLogin(loginStr)
|
||||
c.Data["user"] = u
|
||||
|
||||
c.TplName = "user.tpl"
|
||||
}
|
||||
|
||||
func (c *UserController) Post() {
|
||||
pwd1 := c.Input().Get("password1")
|
||||
pwd2 := c.Input().Get("password2")
|
||||
jid := c.Input().Get("jid")
|
||||
|
||||
if pwd1 == pwd2 {
|
||||
login := c.GetSession(variables.SessionName)
|
||||
switch lo := login.(type) {
|
||||
case string:
|
||||
user.ChangePassword(lo, pwd1)
|
||||
}
|
||||
loginStr := c.getUserLogin()
|
||||
|
||||
user.ChangeJID(loginStr, jid)
|
||||
|
||||
if pwd1 == pwd2 && pwd1 != "" {
|
||||
user.ChangePassword(loginStr, pwd1)
|
||||
}
|
||||
|
||||
c.Redirect(variables.UserRoute, 302)
|
||||
}
|
||||
|
||||
func (c *UserController) getUserLogin() string {
|
||||
ret := ""
|
||||
|
||||
login := c.GetSession(variables.SessionName)
|
||||
switch lo := login.(type) {
|
||||
case string:
|
||||
ret = lo
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
SQLITE = "sqlite"
|
||||
MySQL = "mysql"
|
||||
Alias = "default"
|
||||
SQLITE = "sqlite"
|
||||
MySQL = "mysql"
|
||||
Alias = "default"
|
||||
|
||||
DatabaseInstance = beego.AppConfig.String("database")
|
||||
UserDB = beego.AppConfig.String("mysqluser")
|
||||
|
|
@ -17,9 +17,8 @@ var (
|
|||
RowLimit = 4500
|
||||
)
|
||||
|
||||
|
||||
func init() {
|
||||
row_limit, err = beego.AppConfig.Int64("row_limit")
|
||||
row_limit, err := beego.AppConfig.Int("row_limit")
|
||||
if err == nil {
|
||||
RowLimit = row_limit
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,3 +91,14 @@ func ChangePassword(login, newPwd string) {
|
|||
o.Update(user)
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeJID(login, newJid string) {
|
||||
o := orm.NewOrm()
|
||||
o.Using(database.Alias)
|
||||
|
||||
user := GetUserByLogin(login)
|
||||
if o.Read(user) == nil {
|
||||
user.JID = newJid
|
||||
o.Update(user)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,3 +38,8 @@ body {
|
|||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
.form-signin input[type="text"] {
|
||||
margin-bottom: 30px;
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,18 @@
|
|||
{{define "body"}}
|
||||
<center><h2 class="form-signin-heading">Chagement de mot de passe</h2></center>
|
||||
<form id="chPwdForm" class="form-signin" action="/user" method="POST">
|
||||
<label for="inputEmail" class="sr-only">Mot de passe</label>
|
||||
<input type="password" id="password1" name="password1" class="form-control" placeholder="Password" required>
|
||||
<label for="inputJID" class="sr-only">Jabber ID</label>
|
||||
<input type="text" id="jid" name="jid" class="form-control" placeholder="Jabber ID"
|
||||
{{if .user}}
|
||||
value="{{.user.JID}}"
|
||||
{{end}}
|
||||
>
|
||||
|
||||
<label for="inputPassword" class="sr-only">Mot de passe</label>
|
||||
<input type="password" id="password2" name="password2" class="form-control" placeholder="Password" required>
|
||||
<label for="password1" class="sr-only">Mot de passe</label>
|
||||
<input type="password" id="password1" name="password1" class="form-control" placeholder="Password" >
|
||||
|
||||
<label for="password2" class="sr-only">Mot de passe</label>
|
||||
<input type="password" id="password2" name="password2" class="form-control" placeholder="Password" >
|
||||
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Enregistrer</button>
|
||||
</form>
|
||||
|
|
@ -21,9 +28,17 @@
|
|||
<script src="/static/js/jquery.sha256.min.js"></script>
|
||||
<script type="application/javascript">
|
||||
$("#chPwdForm").submit(function() {
|
||||
$('#password1').val($.sha256($('#password1').val()));
|
||||
var pwd1old = $('#password1').val();
|
||||
var pwd2old = $('#password2').val();
|
||||
if (pwd1old != pwd2old) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pwd1old != "") {
|
||||
$('#password1').val($.sha256(pwd1old));
|
||||
$('#password2').val($.sha256(pwd2old));
|
||||
}
|
||||
console.log("Password1: "+$('#password1').val());
|
||||
$('#password2').val($.sha256($('#password2').val()));
|
||||
console.log("Password2: "+$('#password2').val());
|
||||
|
||||
return $('#password1').val() == $('#password2').val();
|
||||
|
|
|
|||
Loading…
Reference in New Issue