コード例 #1
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $register = new Users();
         $register->id = UUID::v4();
         $register->password = $this->security->hash($this->request->getPost('password'));
         $register->phonenumber = $this->request->getPost('phonenumber');
         $register->email = $this->request->getPost('email');
         $register->name = $this->request->getPost('name');
         $register->created_date = Carbon::now()->now()->toDateTimeString();
         $register->updated_date = Carbon::now()->now()->toDateTimeString();
         $user = Users::findFirstByEmail($register->email);
         if ($user) {
             $this->flash->error("can not register, User " . $register->email . " Alredy Registerd! ");
             return true;
         }
         if ($register->save() === true) {
             $this->session->set('user_name', $register->name);
             $this->session->set('user_email', $register->email);
             $this->session->set('user_id', $register->id);
             $this->flash->success("Your " . $register->email . " has been registered Please Login for booking court");
             $this->response->redirect('dashboard');
         }
     }
 }
コード例 #2
0
 public function passwordResetViaEmailAction()
 {
     $this->response->setContentType('application/json');
     $email = $this->request->getPost('email');
     $user = Users::findFirstByEmail($email);
     if (!$user) {
         $data = array('code' => 1, 'status' => 'error', 'msg' => 'Email Not Found');
     } else {
         $this->getDI()->getMail()->send(array($user->email => $user->email), "Reset Your Password", 'confirmation', array('confirmUrl' => '/change-password/' . $user->email, 'content' => 'You are Almost There! Just Reset Your Password', 'message' => 'please click below to reset your password', 'action' => 'Reset Password'));
         $data = array('code' => 2, 'status' => 'success', 'msg' => 'Mail has been sent to your email please reset your password');
     }
     $this->response->setContent(json_encode($data));
     $this->response->send();
 }
コード例 #3
0
 public function postAction()
 {
     // Check if request has made with POST
     if ($this->request->isPost() == true) {
         $user = Users::findFirstByEmail($this->request->getPost("email"));
         // var_dump($this->security->hash('test5343'));exit;
         if ($user && $this->security->checkHash($this->request->getPost("password"), $user->password)) {
             $this->_registerSession($user);
             $this->response->redirect();
             return;
         }
         $this->flash->error('Wrong email/password');
     }
     $this->response->redirect('login');
 }
コード例 #4
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $username = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = Users::findFirstByEmail($username);
         if ($user->id) {
             if ($this->security->checkHash($password, $user->password)) {
                 $this->session->set('user_name', $user->name);
                 $this->session->set('user_id', $user->id);
                 $this->response->redirect('dashboard');
                 return;
             }
         } else {
             $this->flash->error('Invalid username or password.');
         }
     }
 }
コード例 #5
0
ファイル: SessionController.php プロジェクト: surzm/gohome
 public function startAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = Users::findFirstByEmail($email);
         if ($user) {
             if ($this->security->checkHash($password, $user->password)) {
             } else {
                 $user = false;
             }
         }
         if ($user != false) {
             $this->_registerSession($user);
             $this->flash->success('Welcome ' . $user->name);
             return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         } else {
             $this->flash->error('Неправильный E-mail/пароль');
             return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
         }
     }
 }
コード例 #6
0
 public function loginAction()
 {
     $response = new ApiResponse();
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         // Check if the user exist
         $user = Users::findFirstByEmail($email);
         if ($user == false) {
             $response->setResponseError('Wrong email/password combination 1');
             return $response;
         }
         // Check the password
         if (!$this->security->checkHash($password, $user->password)) {
             $response->setResponseError('Wrong email/password combination');
             return $response;
         }
         $response->setResponse(array('id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'avatar' => $user->avatar));
     } else {
         $response->setResponseError('Wrong HTTP Method');
     }
     return $response;
 }
コード例 #7
0
 public function authAction()
 {
     //parent::initalize();
     if (!$this->request->isPost()) {
         $this->dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
     } else {
         $user = Users::findFirstByEmail($this->request->getPost('email'));
         $password = $this->request->getPost('password');
         if ($user->check_pw($password)) {
             $this->flash->success('Thanks for coming back ' . $user->name);
             return (new \Phalcon\Http\Response())->redirect('/index/index');
             //$this->dispatcher->forward(
             //    array(
             //        'controller'=>'index',
             //        'action'=>'index'
             //    )
             // );
         } else {
             $this->flash->error('Could not authenticate an account with those credentials');
             $this->dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
         }
         //echo (new \Phalcon\Debug\Dump())->variable($user,'user');
     }
 }
コード例 #8
0
 public function admin_addAction()
 {
     if ($this->request->isPost()) {
         $error = 0;
         // if($this->security->checkToken() == false){
         // 	$error = 1;
         // 	$this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Invalid CSRF Token');
         // 	return $this->response->redirect('signup');
         // }
         $firstName = $this->request->getPost('first_name');
         $middleName = $this->request->getPost('middle_name');
         $lastName = $this->request->getPost('last_name');
         $street = $this->request->getPost('street');
         $city = $this->request->getPost('city');
         $country_id = $this->request->getPost('country_id');
         $mobile = $this->request->getPost('mobile');
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         if (empty($firstName) || empty($lastName) || empty($email) || empty($password)) {
             $this->flash->warning('<button type="button" class="close" data-dismiss="alert">×</button>All fields required');
             return $this->response->redirect();
         }
         if (!empty($email) && Users::findFirstByEmail($email)) {
             $errorMsg = "Email is already in use. Please try again.";
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>' . $errorMsg);
             return $this->response->redirect();
         }
         $user = new Users();
         $user->created = date('Y-m-d H:i:s');
         $user->modified = date('Y-m-d H:i:s');
         $user->first_name = $firstName;
         $user->middle_name = $middleName;
         $user->last_name = $lastName;
         $user->mobile = $mobile;
         $user->street = $street;
         $user->city = $city;
         $user->country_id = $country_id;
         $user->email = $email;
         $user->password = $this->security->hash($password);
         if ($user->create()) {
             $activationToken = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 50);
             $emailConfimation = new EmailConfirmations();
             $emailConfimation->created = date('Y-m-d H:i:s');
             $emailConfimation->modified = date('Y-m-d H:i:s');
             $emailConfimation->user_id = $user->id;
             $emailConfimation->email = $email;
             $emailConfimation->token = $activationToken;
             $emailConfimation->confirmed = 'N';
             if ($emailConfimation->save()) {
                 $this->getDI()->getMail()->send(array($email => $firstName . ' ' . $lastName), 'Please confirm your email', 'confirmation', array('confirmUrl' => 'admin/user/emailConfimation/' . $user->id . '/' . $email . '/' . $activationToken));
             }
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>You\'ve successfully created a MyBarangay account. We sent a confirmation email to ' . $email . '.');
         } else {
             //print_r($user->getMessages());
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Registration failed. Please try again.');
         }
         return $this->response->redirect();
     }
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
 }
コード例 #9
0
 public function getPaymentFailerAction()
 {
     $amount = $this->request->getPost('amount');
     $status = $this->request->getPost('status');
     $txnid = $this->request->getPost('txnid');
     $smscredit = $this->request->getPost('udf1');
     $gateway_txnid = $this->request->getPost('payuMoneyId');
     $user = Users::findFirstByEmail($this->request->getPost('email'));
     $transation = TransactionHistory::findFirstByGatewayTxnid($gateway_txnid);
     if (!$transation) {
         $transactionhistory = new TransactionHistory();
         $transactionhistory->amount = $amount;
         $transactionhistory->user_id = $user->id;
         $transactionhistory->sms_credit = $smscredit;
         $transactionhistory->txnid = $txnid;
         $transactionhistory->gateway_txnid = $gateway_txnid;
         $transactionhistory->new_sms_balance = $user->smsbalance->balance;
         $transactionhistory->status = 'FAILED';
         $transactionhistory->created_at = date("Y-m-d H:i:s");
         $transactionhistory->updated_at = date("Y-m-d H:i:s");
         $transactionhistory->save();
         // $this->flash->error($transactionhistory->getMessages());
         $this->response->redirect($this->config->application->apiUri . '/payment-fail/' . $txnid);
     } else {
         $this->response->redirect($this->config->application->apiUri . '/payment-fail/' . $txnid);
     }
 }
コード例 #10
0
 public function changePasswordAction()
 {
     if ($this->request->isPost()) {
         if ($this->request->getPost()) {
             $this->response->setContentType('application/json');
             $email = $this->request->getPost('email');
             $password = $this->request->getPost('password');
             $user = Users::findFirstByEmail($email);
             if (!$user) {
                 $data = array('code' => 1, 'status' => 'error', 'msg' => 'invalid email');
             } else {
                 $user->password = $this->security->hash($password);
                 $user->save();
                 $data = array('code' => 2, 'status' => 'success', 'msg' => 'Password change successfully now you can login');
             }
             $this->response->setContent(json_encode($data));
             $this->response->send();
         }
     }
 }
コード例 #11
0
 public function editUserAction()
 {
     $this->view->disable();
     $inputData = $this->request->getJsonRawBody();
     $userId = $this->dispatcher->getParam("id");
     $user = Users::findFirst($userId);
     $messages = Users::getValidator(false)->validate($inputData);
     if (!$user->id) {
         $this->response->setJsonContent(['status' => 'error', 'data' => 'user not found']);
         $this->response->setStatusCode(401);
         $this->response->send();
     } else {
         if (count($messages)) {
             $errors = [];
             foreach ($messages as $message) {
                 $errors[] = ['message' => $message->getMessage(), 'field' => $message->getField()];
             }
             $this->response->setJsonContent(['status' => 'error', 'data' => $errors]);
             $this->response->setStatusCode(401, 'validation fail');
             $this->response->send();
         } else {
             if ($user->email != $inputData->email && Users::findFirstByEmail($inputData->email)) {
                 $this->response->setJsonContent(['status' => 'error', 'data' => 'email id already in use']);
                 $this->response->setStatusCode(401, 'validation fail');
                 $this->response->send();
             } else {
                 $user->firstName = $inputData->firstName;
                 $user->lastName = $inputData->lastName;
                 $user->email = $inputData->email;
                 $user->gender = $inputData->gender;
                 $user->details = $inputData->details;
                 $user->hobby = serialize($inputData->hobby);
                 $user->save();
                 $this->response->setJsonContent(['status' => 'success', 'data' => 'user updated']);
                 $this->response->setStatusCode(200, "OK");
                 $this->response->send();
             }
         }
     }
 }
コード例 #12
0
ファイル: SessionController.php プロジェクト: freesaga/getit
 /**
  * Registration
  */
 public function registerAction()
 {
     $this->tag->setTitle('Register');
     $request = $this->request;
     if ($request->isPost()) {
         //retrieve POST
         $email = $this->request->getPost('email');
         $emailRetype = $this->request->getPost('emailRetype');
         $password = $this->request->getPost('password');
         $passwordRetype = $this->request->getPost('passwordRetype');
         $username = $this->request->getPost('username');
         $firstname = $this->request->getPost('firstname');
         $lastname = $this->request->getPost('lastname');
         $location = $this->request->getPost('location');
         if ($password != $passwordRetype) {
             //Registration failed, foward to the register form again
             $this->flashSession->error("Passwords do not match");
             $this->response->redirect("session/register");
             $this->view->disable();
         } else {
             if ($email != $emailRetype) {
                 //Registration failed, foward to the register form again
                 $this->flashSession->error("Emails do not match");
                 $this->response->redirect("session/register");
                 $this->view->disable();
             } else {
                 //attempt to create user if not in DB
                 $user = Users::findFirstByUsername($username);
                 if ($user) {
                     //name in use, registration failed
                     $this->flashSession->error("Username already in use");
                     $this->response->redirect("session/register");
                     $this->view->disable();
                 } else {
                     $user = Users::findFirstByEmail($email);
                     if ($user) {
                         //email in use, registration failed
                         $this->flashSession->error("Email already connected to an account");
                         $this->response->redirect("session/register");
                         $this->view->disable();
                     } else {
                         //registration should be good (minus data type stuff)
                         $user = new Users();
                         $user->firstname = $firstname;
                         $user->lastname = $lastname;
                         $user->email = $email;
                         $user->location = $location;
                         $user->username = $username;
                         $user->password = $this->security->hash($password);
                         $user->setCreatedAt();
                         $user->emailConfirmed = 0;
                         if ($user->create()) {
                             //Registration successful, send to login
                             $this->flashSession->success("Registration Successful!");
                             $url = "http://globobug.com/hackgt/session/sendconf/" . $username;
                             $this->response->redirect($url, true);
                             $this->view->disable();
                         } else {
                             foreach ($user->getMessages() as $message) {
                                 $this->flashSession->error($message);
                             }
                             $this->response->redirect("session/register");
                             $this->view->disable();
                         }
                     }
                 }
             }
         }
     }
 }