forked from verdnatura/hedera-web
82 lines
1.9 KiB
JavaScript
Executable File
82 lines
1.9 KiB
JavaScript
Executable File
|
|
Vn.Account = new Class
|
|
({
|
|
Extends: Vn.Module
|
|
|
|
,activate: function ()
|
|
{
|
|
var model = this.get ('user-model');
|
|
model.setTableInfo ('u', 'user_view');
|
|
model.setTableInfo ('c', 'customer_view');
|
|
|
|
this.get ('password').conn = this.conn;
|
|
}
|
|
});
|
|
|
|
Htk.Password = new Class
|
|
({
|
|
Extends: Htk.Widget
|
|
,Tag: 'htk-password'
|
|
|
|
,initialize: function ()
|
|
{
|
|
this.createElement ('div');
|
|
this.node.className = 'htk-password';
|
|
|
|
var passwordEntry = document.createElement ('input');
|
|
passwordEntry.type = 'password';
|
|
passwordEntry.value = '123456';
|
|
passwordEntry.addEventListener ('change', this.passCheckAndChange.bind (this));
|
|
this.node.appendChild (passwordEntry);
|
|
|
|
var repeatEntry = document.createElement ('input');
|
|
repeatEntry.type = 'password';
|
|
repeatEntry.addEventListener ('change', this.passCheckAndChange.bind (this));
|
|
this.node.appendChild (repeatEntry);
|
|
|
|
var logNode = document.createElement ('span');
|
|
this.node.appendChild (logNode);
|
|
|
|
this.logNode = logNode;
|
|
this.passwordEntry = passwordEntry;
|
|
this.repeatEntry = repeatEntry;
|
|
}
|
|
|
|
,passCheckAndChange: function ()
|
|
{
|
|
var newPassword = this.passwordEntry.value;
|
|
var repeatedPassword = this.repeatEntry.value;
|
|
|
|
Vn.Node.removeChilds (this.logNode);
|
|
|
|
if (newPassword != '' && repeatedPassword != '')
|
|
{
|
|
if (newPassword !== repeatedPassword)
|
|
{
|
|
this.logNode.style.color = 'red';
|
|
Vn.Node.setText (this.logNode, _('PasswordsDoesntMatch'));
|
|
}
|
|
else
|
|
{
|
|
var batch = new Sql.Batch ();
|
|
batch.addValue ('password', newPassword);
|
|
|
|
var query = 'UPDATE user_view SET password = MD5(#password) '
|
|
+'WHERE id = account.user_get_id () LIMIT 1';
|
|
|
|
this.conn.execQuery (query, this.passUpdated.bind (this), batch);
|
|
}
|
|
}
|
|
}
|
|
|
|
,passUpdated: function (resultSet)
|
|
{
|
|
if (!resultSet.fetchResult ())
|
|
return;
|
|
|
|
this.logNode.style.color = 'green';
|
|
Vn.Node.setText (this.logNode, _('PasswordsChanged'));
|
|
}
|
|
});
|
|
|