Exemple #1
0
 /**
  * @param $fields
  * @return bool
  */
 public function signupValidation($fields = array())
 {
     $errors = null;
     if (isset($fields->name) && $this->applyValidationRules('notEmpty', $fields->name) == false) {
         $errors['name'] = 'Name must be required';
     }
     if (isset($fields->email) && $this->applyValidationRules('notEmpty', $fields->email) == false) {
         $errors['email'] = 'Email must be required';
     }
     if (isset($fields->email) && $this->applyValidationRules('email', $fields->email) == false) {
         $errors['email'] = 'Please provide valid email address';
     }
     if (isset($fields->email) && !isset($errors['email'])) {
         $user = new Users();
         $isExist = $user->whereEmail($fields->email)->first();
         if ($isExist) {
             $errors['email'] = 'This email is already taken';
         }
     }
     if (isset($fields->password) && $this->applyValidationRules('notEmpty', $fields->password) == false) {
         $errors['password'] = '******';
     }
     if (isset($fields->cPassword) && $this->applyValidationRules('notEmpty', $fields->cPassword) == false) {
         $errors['cPassword'] = '******';
     }
     if (isset($fields->cPassword) && $this->applyValidationRules('matchPassword', $fields->cPassword, $fields) == false) {
         $errors['cPassword'] = '******';
     }
     return $errors;
     /**
      * TODO validation script should write in proper way
      */
 }
Exemple #2
0
<?php

use Model\Users;
$app->post('/users', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $user->uuid = \Lib\App::v4();
    $user->name = $data->name;
    $user->email = $data->email;
    $user->password = password_hash($data->password, PASSWORD_BCRYPT);
    $user->save();
    echo json_encode($data);
});
$app->post('/users/login', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $result = $user->where('email', $data->email)->first();
    echo json_encode($result);
});
$app->post('/users/is_email_unique', function () use($app) {
    $data = json_decode(file_get_contents("php://input"));
    $user = new Users();
    $isExist = $user->whereEmail($data->email)->first();
    echo json_encode($isExist);
});