コード例 #1
0
ファイル: UserModel.php プロジェクト: berksonj/bet
 public function registration()
 {
     $bookhouse = new Model_BookhouseModel();
     $bookhouse->loadActiveBookhouse();
     if ($bookhouse->getCanUserRegister() == 0) {
         $this->setValidationError('Bookhouse', 'Registration is disabled');
     }
     $userCheckModel = new Model_UserModel();
     $userCheckModel->load(array('user_name' => $this->getUserName()));
     $userId = $userCheckModel->getUserId();
     if (isset($userId)) {
         $this->setValidationError('username', 'Username already exist');
         return;
     }
     $userCheckModel->load(array('email' => $this->getEmail()));
     $userId = $userCheckModel->getUserId();
     if (isset($userId)) {
         $this->setValidationError('username', 'Email already exist');
         return;
     }
     $this->setLastLogin(date('Y-m-d H:i:s'));
     $this->setUserStatusIdFK(3);
     $this->setBanned(0);
     $this->setEmailValidated(0);
     $this->insert();
     $userIdFK = $this->getConnection()->getInsertId();
     $transaction = new Model_TransactionModel();
     $transaction->setUserIdFK($userIdFK);
     $transaction->setTransactionTypeIdFK(1);
     $transaction->setMoney($bookhouse->getDefaultMoneyValue());
     $transaction->setTransactionTypeIdendifier(null);
     $transaction->insert();
 }
コード例 #2
0
ファイル: Servicejson.php プロジェクト: berksonj/bet
 public function actionLogin()
 {
     $this->preventTemplateRender();
     $user = new Model_UserModel();
     $isVarsSet = true;
     if (!isset($_REQUEST['username'])) {
         $user->setValidationError('username', 'Username not set');
         $isVarsSet = false;
     }
     if (!isset($_REQUEST['password'])) {
         $user->setValidationError('password', 'Password not set');
         $isVarsSet = false;
     }
     if (!$isVarsSet) {
         echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
         return;
     }
     $user->setUserName($_REQUEST['username']);
     $user->setPasswordBeforeSalt($_REQUEST['password']);
     $user->validateFields(array('user_name', 'password_before_salt'));
     if ($user->isValid()) {
         if (!$user->login()) {
             echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
         } else {
             $userSession = new Core_Auth_User();
             $userSession->setData($user->getData());
             $userStatus = new Model_UserStatusModel();
             $userStatus->load($user->getUserStatusIdFK());
             $userSession->isAuth(true);
             $userSession->setRole($userStatus->getStatusName());
             if (Application::getSessionType() == Application::SESSION_TYPE_DB) {
                 $storage = new Model_SessionStorageModel();
                 $storage->setUserId($user->getUserId());
                 $storage->setHash(session_id());
                 $storage->insert();
             }
             exit(session_id());
             echo json_encode(array('status' => 'ok'));
         }
     } else {
         echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors()));
     }
 }