Ejemplo n.º 1
0
<?php

use app\models\Users;
use lithium\security\Password;
Users::applyFilter('save', function ($self, $params, $chain) {
    if ($params['data']) {
        $params['entity']->set($params['data']);
        $params['data'] = array();
    }
    if (!$params['entity']->exists()) {
        $params['entity']->password = Password::hash($params['entity']->password);
    }
    return $chain->next($self, $params, $chain);
});
Ejemplo n.º 2
0
        return false;
    }
});
Validator::add('uniqueUsername', function ($value, $rule, $options) {
    $conflicts = Users::count(array('username' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Validator::add('uniqueEmail', function ($value, $rule, $options) {
    $conflicts = Users::count(array('email' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Users::applyFilter('save', function ($self, $params, $chain) {
    if ($params['data']) {
        $params['entity']->set($params['data']);
        $params['data'] = array();
    }
    if (!$params['entity']->exists()) {
        $params['entity']->password = String::hash($params['entity']->password);
        $params['entity']->password2 = String::hash($params['entity']->password2);
        $params['entity']->created = new \MongoDate();
        $params['entity']->updated = new \MongoDate();
        $params['entity']->ip = $_SERVER['REMOTE_ADDR'];
    }
    return $chain->next($self, $params, $chain);
});
Ejemplo n.º 3
0
Validator::add('uniqueWalletID', function ($value, $rule, $options) {
    $conflicts = Users::count(array('walletid' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Validator::add('uniqueEmail', function ($value, $rule, $options) {
    $conflicts = Users::count(array('email' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Validator::add('uniqueUsername', function ($value, $rule, $options) {
    $conflicts = Users::count(array('username' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Users::applyFilter('save', function ($self, $params, $chain) {
    if ($params['data']) {
        $params['entity']->set($params['data']);
        $params['data'] = array();
    }
    if (!$params['entity']->exists()) {
        $params['entity']->created = new \MongoDate();
    }
    return $chain->next($self, $params, $chain);
});
Ejemplo n.º 4
0
<?php

use app\models\Users;
use lithium\security\Password;
Users::applyFilter('save', function ($self, $params, $chain) {
    if ($params['data']) {
        $params['entity']->set($params['data']);
        $params['data'] = array();
    }
    $record = $params['entity'];
    //password is provided, we need to hash it
    if (!empty($record->password)) {
        $record->password = lithium\util\String::hash($record->password);
    }
    return $chain->next($self, $params, $chain);
});
Ejemplo n.º 5
0
}
Validator::add('passwordVerification', function ($value, $rule, $options) {
    if (!isset($options['values']['password2']) || $value == $options['values']['password2']) {
        return true;
    }
    return false;
});
Validator::add('uniqueUsername', function ($value, $rule, $options) {
    $conflicts = Users::count(array('username' => $value));
    if ($conflicts) {
        return false;
    }
    return true;
});
Users::applyFilter('save', function ($self, $params, $chain) {
    $entity = $params['entity'];
    $data = $params['data'];
    if ($data) {
        $entity->set($data);
        if (isset($data['password']) && $data['password'] && isset($data['password2']) && $data['password2']) {
            $entity->password = \lithium\util\String::hash($data['password']);
            $entity->password2 = \lithium\util\String::hash($data['password2']);
        }
    }
    if (!$entity->id) {
        $entity->created = new \MongoDate();
    }
    $entity->updated = new \MongoDate();
    $params['entity'] = $entity;
    return $chain->next($self, $params, $chain);
});