2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
Vn.Account = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Module
|
|
|
|
|
|
|
|
,activate: function ()
|
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
var model = this.$('user-model');
|
2015-01-23 13:09:30 +00:00
|
|
|
model.setTableInfo ('u', 'user_view');
|
|
|
|
model.setTableInfo ('c', 'customer_view');
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.$('user-form').on ('iter-changed', this.onUserDataReady, this);
|
|
|
|
this.$('new-password').addEventListener ('change', this.onPasswordChange.bind (this));
|
|
|
|
this.$('repeat-password').addEventListener ('change', this.onPasswordChange.bind (this));
|
|
|
|
this.$('user-name').addEventListener ('change', this.onUserChange.bind (this));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-03-06 23:33:54 +00:00
|
|
|
|
|
|
|
,onUserDataReady: function (form)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
this.$('user-name').value = form.get ('name');
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-03-06 23:33:54 +00:00
|
|
|
|
|
|
|
,onUserChange: function ()
|
|
|
|
{
|
|
|
|
if (!confirm (_('MustReloginIfChange')))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var batch = new Sql.Batch ();
|
|
|
|
batch.addValue ('name', this.$('user-name').value);
|
|
|
|
|
|
|
|
var query = 'UPDATE user_view SET name = #name '
|
|
|
|
+'WHERE id = account.user_get_id () LIMIT 1';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.conn.execQuery (query, this.onUserUpdate.bind (this), batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
,onUserUpdate: function (resultSet)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
if (!resultSet.fetchResult ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
location.reload ();
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
,onPasswordChange: function ()
|
|
|
|
{
|
|
|
|
var newPassword = this.$('new-password').value;
|
|
|
|
var repeatedPassword = this.$('repeat-password').value;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (newPassword != '' && repeatedPassword != '')
|
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
if (newPassword === repeatedPassword)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.conn.execQuery (query, this.onPasswordUpdate.bind (this), batch);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-03-06 23:33:54 +00:00
|
|
|
else
|
|
|
|
(new Htk.Toast ()).showError (_('PasswordsDoesntMatch'));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
,onPasswordUpdate: function (resultSet)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
if (!resultSet.fetchResult ())
|
|
|
|
return;
|
2015-03-06 23:33:54 +00:00
|
|
|
|
|
|
|
this.relogin ();
|
|
|
|
(new Htk.Toast ()).showMessage (_('PasswordsChanged'));
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
,relogin: function ()
|
|
|
|
{
|
|
|
|
this.conn.open (
|
|
|
|
this.$('user-form').get ('name')
|
|
|
|
,this.$('new-password').value
|
|
|
|
,Vn.Cookie.check ('vn_pass')
|
|
|
|
);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|