예제 #1
0
 public function registerAction()
 {
     if ($this->request->isPost()) {
         if ($this->token->check()) {
             $email = $this->request->getPost('email');
             $password = $this->request->getPost('password');
             $this->installRoles();
             $this->installResourcesAccess();
             $this->installUserStatus();
             $admin = new Users();
             $admin->email = $email;
             $admin->password = $this->security->hash($this->auth->passwordHash($password));
             $admin->status_id = UsersStatus::findFirstByName(Auth::STATUS_ACTIVE)->id;
             $admin->role = Auth::ROLE_ADMIN;
             if ($admin->save() !== false) {
                 $this->flashSession->success(_('Administrator user is successfully created'));
                 $this->redirect();
             } else {
                 foreach ($admin->getMessages() as $message) {
                     $this->flash->error($message);
                 }
             }
         }
     }
 }
예제 #2
0
 public function getCustomersAction()
 {
     if ($this->request->isPost()) {
         if ($this->request->isAjax()) {
             if ($this->token->check('token')) {
                 $customers = Customers::find()->toArray();
                 $response = array();
                 foreach ($customers as $customer) {
                     $bookkeper = Users::findFirstById($customer['bookkeeper_id']);
                     $customer['gruppo'] = CustomersGroups::findFirstById($customer['customers_groups_id'])->nome;
                     $customer['contabile'] = $bookkeper->details->name . ' ' . $bookkeper->details->surname;
                     $customer['stato'] = CustomersState::findFirstById($customer['customers_state_id'])->stato;
                     $response[] = $customer;
                 }
                 return $this->sendAjax(array("data" => $response));
             }
         }
     }
 }
예제 #3
0
파일: Auth.php 프로젝트: skullab/area51
    public function forgotPassword($email)
    {
        $user = Users::findFirstByEmail($email);
        if ($user == false) {
            throw new Auth\Exception(null, 300);
        }
        $publicKey = Crypto::createNewRandomKey();
        $privateKey = Crypto::createNewRandomKey();
        $token = Crypto::encrypt($privateKey, $publicKey);
        $encodedPublicKey = rawurlencode($publicKey);
        $encodedToken = rawurlencode($token);
        $expire = date("Y-m-d H:i:s", time() + TIME_ONE_HOUR);
        //
        $forgot = new UsersForgotPassword();
        $forgot->users_id = $user->id;
        $forgot->private_key = $privateKey;
        $forgot->token = $token;
        $forgot->expires = $expire;
        if ($forgot->save() == false) {
            foreach ($forgot->getMessages() as $message) {
                $this->flash->error($message);
            }
            return false;
        }
        //
        $this->mail->setTo([$email]);
        $this->mail->setSubject('reset password');
        $this->mail->setBody('
				<div>
					<a href="http:' . $this->url->getStaticBaseUri() . 'reset-password?k=' . $encodedPublicKey . '&t=' . $encodedToken . '">reset your passsword here</a>
				</div>
		');
        $this->mail->send();
        //echo '<a href="'.$this->url->getStaticBaseUri().'reset-password?k='.$encodedPublicKey.'&t='.$encodedToken.'">reset your passsword here</a>' ;
        if (empty($this->mail->getFailedRecipients())) {
            $this->flash->success('email sent. check your inbox');
        } else {
            $this->flash->error('an error occured');
        }
    }
예제 #4
0
 public function profileAction($id, $change = null, $value = null)
 {
     if (is_numeric($id)) {
         $user = Users::findFirstById($id);
         if ($user) {
             if ($this->request->isPost()) {
                 if ($this->request->isAjax()) {
                     $payload = array('error' => 0);
                     $field = $this->request->getPost('name');
                     $value = $this->request->getPost('value');
                     if (!$user->details) {
                         $user->details = new UsersDetails();
                         $user->details->users_id = $user->id;
                     }
                     if ($field == 'role') {
                         $user->acl_roles_name = $value;
                     } else {
                         $user->details->{$field} = $value;
                     }
                     try {
                         if ($user->save() == false) {
                             $payload['error'] = 1;
                             foreach ($user->getMessages() as $message) {
                                 $payload['message'] .= $message . '<br>';
                             }
                         }
                     } catch (\Exception $e) {
                         $payload['error'] = $e->getCode();
                         $payload['message'] = $e->getMessage();
                     }
                     return $this->sendAjax($payload);
                 }
             }
             $this->cssPlugins->addCss('css/pages/profile.css')->addCss('vendor/x-editable/x-editable.css')->addCss('vendor/typeahead-js/typeahead.css')->addCss('vendor/select2/select2.css');
             $this->jsPlugins->addJs('vendor/x-editable/bootstrap-editable.js')->addJs('vendor/typeahead-js/bloodhound.min.js')->addJs('vendor/typeahead-js/typeahead.jquery.min.js')->addJs('vendor/x-editable/address.js')->addJs('vendor/select2/select2.min.js')->addJs('vendor/moment/moment.min.js');
             $this->loadInlineActionJs(array('user' => $user));
             //$this->assets->renderInlineJs('js/controllers/userProfile.js',true,array('user'=>$user));
             $this->view->body_class = 'page-profile';
             $this->view->user = $user;
         } else {
             $this->redirect();
         }
     } else {
         $this->redirect();
     }
 }
예제 #5
0
파일: Users.php 프로젝트: skullab/area51
 public static function getProgressiveCode($maxLength = 7, $substitute = 0)
 {
     $max = Users::maximum(array('column' => 'id'));
     $code = str_pad((int) substr($max, -4) + 1, $maxLength, $substitute, STR_PAD_LEFT);
     return $code;
 }