public function testGetByEmail() { $u = new User($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost'))); $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => ''))); $this->assertNotEmpty($u->getByEmail('user1@localhost')); $this->assertEmpty($u->getByEmail('')); }
public function resetAction() { //Extracting RedirectURL $redirectUrl = $this->getBag->get('redirect'); //base64 encoded if (strlen($redirectUrl) > 0) { $redirectUrl = base64_decode($redirectUrl); } elseif ($this->getBag->has('returnurl') && $this->getBag->get('returnurl') != '') { $redirectUrl = urldecode($this->getBag->get('returnurl')); } else { $redirectUrl = $this->registry->conf['rooturl']; } $error = $warning = $formData = array(); $email = $this->getBag->get('email'); $activatedCode = $this->getBag->get('code'); //Found user by email $myUser = \Model\User::getByEmail(urldecode($email)); if ($myUser->id > 0) { if ($myUser->activatedcode != $activatedCode && false) { $this->notfound(); } else { if ($this->postBag->has('fsubmit')) { $formData = $this->postBag->all(); if ($formData['fpassword'] != $formData['fpassword2']) { $error[] = 'Passwords are not matched.'; } else { if (strlen($formData['fpassword']) < 6) { $error[] = 'Password is at least 6 characters.'; } else { $myUser->newpass = $this->postBag->get('fpassword'); $myUser->activatedcode = ''; if ($myUser->updateData()) { $success[] = 'Your password had been saved.'; $successUrl = $this->registry->conf['rooturl'] . 'login?from=forgotpass&email=' . $myUser->email . '&redirect=' . base64_encode($redirectUrl); $this->doRedirect($successUrl); } else { $error[] = 'Error while changing your password'; } } } //end validate form } //end submit if (empty($success)) { $this->registry->smarty->assign(array('formData' => $formData, 'myUser' => $myUser, 'error' => $error, 'warning' => $warning, 'redirectUrlEncode' => base64_encode($redirectUrl))); $contents = $this->registry->smarty->display($this->registry->smartyController . 'reset.tpl'); $this->registry->response->setContent($contents); } } } else { $this->notfound(); } }
public function indexAction() { $error = $warning = $formData = array(); $redirectUrl = $this->registry->request->query->get('redirect'); //base64 encoded $isLoginSuccess = false; if ($this->registry->request->request->has('fsubmit')) { $formData = array_merge($formData, $this->registry->request->request->all()); $myUser = \Model\User::getByEmail($formData['femail']); if ($myUser->id > 0 && $myUser->password == \Litpi\ViephpHashing::hash($formData['fpassword'])) { $isLoginSuccess = true; $redirectUrl = $this->doLogin($myUser->id, $formData['fpassword'], $redirectUrl); $this->doRedirect($redirectUrl); } else { $error[] = $this->registry->lang['controller']['errAccountInvalid']; } } if (!$isLoginSuccess) { $this->registry->smarty->assign(array('formData' => $formData, 'error' => $error, 'redirectUrl' => $redirectUrl)); $contents = $this->registry->smarty->fetch($this->registry->smartyController . 'index.tpl'); $this->registry->response->setContent($contents); } }
private function addActionValidator($formData, &$error) { $pass = true; if ($formData['fgroupid'] == 0) { $error[] = $this->registry->lang['controller']['errGroupInvalid']; $pass = false; } //kiem tra email co dung dinh dang hay khong :validateEmail if (!Helper::validateEmail($formData['femail'])) { $error[] = $this->registry->lang['controller']['errEmailInvalid']; $pass = false; } else { //kiem tra co trung email hay khong if (\Model\User::getByEmail($formData['femail'])->id > 0) { $error[] = $this->registry->lang['controller']['errEmailExisted']; $pass = false; } } //kiem tra password if ($formData['fpassword'] == '') { $error[] = $this->registry->lang['controller']['errPasswordRequired']; $pass = false; } elseif ($formData['fpassword'] != $formData['fpassword2']) { //nhap lai password khong dung nhu password dau $error[] = $this->registry->lang['controller']['errPasswordRetype']; $pass = false; } if ($formData['ffullname'] == '') { $error[] = $this->registry->lang['controller']['errFullnameRequired']; $pass = false; } return $pass; }