Skip to content

Commit

Permalink
login fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Barile committed Feb 17, 2014
1 parent 19d7a9b commit 06bf51e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 60 deletions.
5 changes: 4 additions & 1 deletion auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ function authenticate_user()
$data = parse_post_body();

if(ow_login($data['username'], $data['password'], @$data['remember'] == 1)) {
return "Ok";
return ow_user();
}
else {
respond('Invalid login name or password', 403);
};


Expand Down
4 changes: 2 additions & 2 deletions console/app/modules/auth/loginWindow/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ define(['Boiler', 'text!./view.html'], function (Boiler, template) {
$('#login-window button').button('loading');

moduleContext.notify('login', {
identifier: $('#login-form .identifier').val(),
username: $('#login-form .username').val(),
password: $('#login-form .password').val()
});

Expand All @@ -50,7 +50,7 @@ define(['Boiler', 'text!./view.html'], function (Boiler, template) {

}
panel.show();
$('#login-form .identifier').focus();
$('#login-form .username').focus();
},
deactivate:function () {

Expand Down
2 changes: 1 addition & 1 deletion console/app/modules/auth/loginWindow/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3 id="myModalLabel">Login</h3>
</div>
<p>Acesso</p>

<label>Login:</label><input type='text' class="identifier">
<label>Login:</label><input type='text' class="username">
<label>Senha:</label><input type='password' class="password">
<div class="alert alert-error authfail hide">
Login/senha incorretos
Expand Down
2 changes: 1 addition & 1 deletion console/app/modules/auth/userMenu/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a class="dropdown-toggle"
data-toggle="dropdown"
href="#">
<span data-bind="text: current_user().displayName || current_user().identifier"></span>
<span data-bind="text: (current_user().profile && current_user().profile.name) || current_user().username"></span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
Expand Down
9 changes: 5 additions & 4 deletions lib/backend/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function query($query, $mapper = null)
if ($mapper) {
while($data = $result->fetch_assoc()) {
$r = call_user_func($mapper, $data);
$results[] = $r;
}
$results[] = $r;
} else {
while ($data = $result->fetch_row()) {
/* Get field information for all columns */
Expand Down Expand Up @@ -86,8 +86,9 @@ function query($query, $mapper = null)
}
}
}
$results[] = $r;
}
$results[] = $r;

}
}

Expand Down Expand Up @@ -810,9 +811,9 @@ function fetch($params = array())
$this->belongsTo['owner'] = array(
'table' => OW_DIRECTORY,
// 'fields' => array('oid', 'displayName', 'identifier', 'photoURL', 'created'),
// $value is a field on the main table
'key' => array(
'oid' => '_owner',
'namespace' => ''
'oid' => '_owner'
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ function get($id, $data) {
* @param $data Array with the new resource contents
* @return Array Modified data which will be persisted
*/
function post($data) {
function post($id, $data) {

return $data;
}
Expand Down
83 changes: 33 additions & 50 deletions lib/directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

// Default directory table
defined('OW_DIRECTORY') or define('OW_DIRECTORY', 'ow_directory');
defined('OW_DIRECTORY') or define('OW_DIRECTORY', 'ow_aro');

defined('OW_SESSION_KEY') or define('OW_SESSION_KEY', 'OW_AUTH');

Expand Down Expand Up @@ -47,17 +47,13 @@ function accounts_mapper($data)

// Register the "directory" domain
register_domain('directory', array(
'table' => "ow_aro",
'table' => OW_DIRECTORY,
'handler' => 'TableStore',
'hasMany' => array(
'accounts' => array(
'table' => 'ow_accounts',
'key' => 'aro_id',
'mapper' => 'accounts_mapper'
),
'meta' => array(
'table' => 'ow_directory',
'key' => 'aro_id'
)
),
'mapper' => 'directory_mapper',
Expand All @@ -69,54 +65,26 @@ function accounts_mapper($data)

function directory_mapper($data)
{
return array(
'id' => $data['id'],
'username' => $data['value'],
'email' => $data['name'],
'date_created' => $data['date_created'],
'last_login' => $data['last_login']
);
}

function directory_get($self, $id)
{
if (is_numeric($id) || is_array($id)) {
return $self->get($id);
} else {
$entries = $self->fetch("oid=$id");
if (count($entries)) {
$result = array('oid' => $id);
foreach ($entries as $entry) {
if (empty($entry['namespace'])) {
foreach ($entry as $k => $v) {
$result[$k] = $v;
}
} else {
$result[$entry['namespace']] = $entry;
}
}
} else {
$result = null;
}

return $result;
if(!empty($data['oid'])) {
return array(
'id' => $data['id'],
'oid' => $data['oid'],
'username' => $data['value'],
'email' => $data['name'],
'date_created' => $data['date_created'],
'last_login' => $data['last_login'],
'profile' => json_decode($data['profile'], true)
);
}
}

function directory_password_filter($data)
{
if (empty($data['namespace']) && !empty($data['password'])) {
$data['userPassword'] = md5($data['password']);
unset($data['password']);
else {
return $data;
}

return $data;
}

function directory_post($handler, $data)
{

if ($data['password'] != $data['confirm']) {
if (isset($data['confirm']) && $data['password'] != $data['confirm']) {
throw new Exception('Passwords don\'t match');
}

Expand All @@ -131,13 +99,16 @@ function directory_post($handler, $data)
$now = ulUtils::nowstring();
$past = date_format(date_create('1000 years ago'), UL_DATETIME_FORMAT);


$aro = $handler->post(array(
'name' => $data['email'],
'value' => $data['username'],
'oid' => empty($data['oid']) ? ow_oid() : $data['oid'],
'password' => $hashed_password,
'date_created' => $now,
'last_login' => $now,
'block_expires' => $past
'block_expires' => $past,
'profile' => empty($data['profile']) ? '{}' : $data['profile']
));

$accounts = ow_user('accounts');
Expand All @@ -158,7 +129,19 @@ function directory_put($self, $id, $data)
throw new Exception("Invalid ID for put (must be numeric)", 405);
}

return $self->put($id, directory_password_filter($data));
$put = array(
'name' => $data['email'],
'profile' => $data['profile']
);

if(!empty($data['password'])) {
if (isset($data['confirm']) && $data['password'] != $data['confirm']) {
throw new Exception('Passwords don\'t match');
}
$put['password'] = ulPassword::Hash($data['password'], UL_PWD_FUNC);
}

return $self->put($id, $put);
}


Expand Down Expand Up @@ -242,7 +225,7 @@ class Acl extends OWService

var $id = "acl";

function post($data)
function post($id, $data)
{

$current_user = ow_user();
Expand Down

0 comments on commit 06bf51e

Please sign in to comment.