public function actionAddcompany() { $companyModel = new Company(); $userLoginModel = new UserLogin(); $userProfileModel = new UserProfile(); if (isset($_POST['Company'])) { $companyModel->attributes = $_POST['Company']; $userLoginModel->attributes = $_POST['UserLogin']; $userProfileModel->attributes = $_POST['UserProfile']; if ($companyModel->validate()) { if ($companyModel->save()) { $userLoginModel->UserRoleID = 2; // $userLoginModel->LoginEmail = '*****@*****.**'; $userLoginModel->UserPassword = md5($userLoginModel->UserPassword); $userLoginModel->IsPasswordReset = 1; $userLoginModel->IsActive = 1; $userLoginModel->save(); $userProfileModel->UserLoginID = $userLoginModel->UserLoginID; $userProfileModel->CompanyID = $companyModel->CompanyID; // $userProfileModel->FirstName = 'Test'; // $userProfileModel->LastName = 'test'; $userProfileModel->AgreeToTerms = 0; $userProfileModel->IsFacilitator = 0; $userProfileModel->save(); $this->redirect(Yii::app()->createUrl('admin/setup', array('id' => $companyModel->CompanyID))); } } } $this->render('add-company', array('companyModel' => $companyModel, 'userLoginModel' => $userLoginModel, 'userProfileModel' => $userProfileModel)); }
/** * @fn login * @short Action method to perform a login. */ function login() { if ($this->request->is_post()) { $conn = Db::get_connection(); $user_factory = new User(); $users = $user_factory->find_all(array('where_clause' => "`username` = '{$conn->escape($_POST['username'])}' AND `password` = '" . md5($_POST['password']) . "'", 'limit' => 1)); if (count($users) > 0) { $user = $users[0]; $expires = $_POST['leave_me_registered'] ? Time::next_year() : Time::tomorrow(); Cookie::set('_u', $user->username, $expires, "/", FALSE); Cookie::set('_uid', md5(Login::magic_phrase . $user->password), $expires, "/", FALSE); // Annotates the login in the database $user_login = new UserLogin(); $user_login->user_id = $user->id; $user_login->performed_at = date("Y-m-d H:i:s"); $user_login->save(); $this->flash(sprintf(l('Welcome, %s'), $user->first), 'info'); // When login is required to access a particular action, we may store controller & action in a session, // perform login, then redirect to the action requested in the first place if (isset($_SESSION['redirect_to'])) { $this->redirect_to(array('controller' => $_SESSION['redirect_to']['controller'], 'action' => $_SESSION['redirect_to']['action'])); } else { $this->redirect_to(array('controller' => 'home')); } Db::close_connection($conn); } else { $this->flash(l('Bad username / password'), 'error'); } } $this->redirect_to(array('action' => 'index')); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserLogin(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['UserLogin'])) { $model->attributes = $_POST['UserLogin']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->user_id)); } } $this->render('create', array('model' => $model)); }
public function actionIndex() { //获取用户名和密码 $name = Yii::app()->request->getParam('name'); $password = Yii::app()->request->getParam('password'); if (!$name) { Error::output(Error::ERR_NO_USER_NAME); } if (!$password) { Error::output(Error::ERR_NO_PASSWORD); } //获取用户模型 $userinfo = Members::model()->find('name=:name', array(':name' => $name)); if (!$userinfo) { Error::output(Error::ERR_NO_USER); } else { $_password = md5($userinfo->salt . $password); if ($_password != $userinfo->password) { Error::output(Error::ERR_INVALID_PASSWORD); } } //登陆成功生成user_login $userLogin = UserLogin::model()->find('user_id = :user_id', array(':user_id' => $userinfo->id)); if (!$userLogin) { //不存在就创建 $userLogin = new UserLogin(); $userLogin->user_id = $userinfo->id; $userLogin->username = $name; } $userLogin->login_time = time(); $userLogin->token = md5(time() . Common::getGenerateSalt()); $userLogin->visit_client = Common::getClientType(); $userLogin->ip = Common::getIp(); $userLogin->save(); $member = CJSON::decode(CJSON::encode($userinfo)); $member['token'] = $userLogin->token; unset($member['password'], $member['salt']); //返回数据 //如果存在头像,就返回 if ($member['avatar']) { //取图片数据 $material = Material::model()->findByPk($member['avatar']); $member['avatar'] = array('host' => Yii::app()->params['img_url'], 'filepath' => $material->filepath, 'filename' => $material->filename); } Out::jsonOutput($member); }
/** * Create new user * * @param array $data, POST data * @return int $id, current id of created user */ public function saveLoginDataTab(array $data){ $userObj = new UserLogin(); $userObj->setUsername($data['userFirstTab_username']); $userObj->setEmail($data['userFirstTab_email']); $userObj->setRoleId($data['userFirstTab_userrole']); $userObj->setPassword($data['userFirstTab_password']); $userObj->save(); $id = $userObj->getId(); $userData = new UserData(); $userData->setUserId($id); $userData->setFirstname($data['userFirstTab_firstname']); $userData->setLastname($data['userFirstTab_lastname']); $userData->save(); $userSetting= new UserSetting(); $userSetting->setUserId($id); $userSetting->setEmailformat($data['userFirstTab_emailformat']); $userSetting->setEmailtype($data['userFirstTab_emailtype']); $userSetting->setLanguage($data['userFirstTab_language']); $userSetting->setFirstlogin(1); $userSetting->save(); return $id; }
public function crt_admin() { $validate = UserLogin::validate(Input::all()); $validatedetails = UserDetails::validate(Input::all()); if ($validate->passes() and $validatedetails->passes()) { $defaultimg = 'default.png'; $userleave = new LeaveCounter(); $userleave->employee_id = Input::get('employeeid'); $userleave->remaining_leave = 10; $userleave->remaining_leave_wopay = 10; $userleave->save(); $userlogin = new UserLogin(); $userlogin->employee_id = Input::get('employeeid'); $userlogin->username = Input::get('username'); $userlogin->password = Hash::make(Input::get('password')); $userlogin->role = 'Administrator'; $userlogin->save(); $userdetails = new UserDetails(); $userdetails->employee_id = Input::get('employeeid'); $userdetails->firstname = Input::get('firstname'); $userdetails->surname = Input::get('surname'); $userdetails->profile_mage = 'img/' . $defaultimg; $userdetails->e_status = 'Administrator'; $userdetails->department = Input::get('department'); $userdetails->email = Input::get('email'); $userdetails->save(); return Redirect::route('create_admin')->with('message', 'Registered Successfully!'); } else { $validation = array_merge_recursive($validate->messages()->toArray(), $validatedetails->messages()->toArray()); return Redirect::route('create_admin')->withErrors($validation)->withInput(); } }
public function actionCreate() { // check permissions // if (!Yii::app()->user->checkAccess('manageUser')) { // Helper::authException(); // } // models $UserLogin = new UserLogin(); $UserProfile = new UserProfile(); // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'godAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('godAdministrator')) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = array('' => '') + $rolesArray; // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->IsPasswordReset = 1; // force password reset on first login $UserLogin->IsActive = 1; $UserLogin->scenario = 'create'; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; $UserProfile->CompanyID = Yii::app()->user->companyID; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } // save UserProfile $UserProfile->UserLoginID = $UserLogin->UserLoginID; // set newly generated EventID if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } // set success message for user Yii::app()->user->setFlash('success', 'A new user was successfully created.'); // return to empty create user form if adding another, else go to user dashboard if (isset($_POST['button-submit-add'])) { $this->redirect($this->createUrl('user/create')); } else { $this->redirect($this->createUrl('user/dashboard')); } } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray)); }
public function actionCreate() { // check permissions // if (!Yii::app()->user->checkAccess('manageUser')) { // Helper::authException(); // } // models $UserLogin = new UserLogin(); $UserProfile = new UserProfile(); $criteria3 = new CDbCriteria(); $criteria3->condition = '(companyID = :companyID AND IsActive=1)'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3); $managersArray = array(); $managersArray[0] = "Please Select..."; foreach ($userManagers as $UserManager) { //if ($UserManager->ManagerEmail == '') { //$managersArray[$UserManager->Email] = $UserManager->Email; $managersArray[$UserManager->Email] = $UserManager->Email; //} elseif (Helper::hasRole('lacekAdministrator')) { // $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; // } } // add default (empty value) to front of array $managerArray = $managersArray; // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'lacekAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('lacekAdministrator')) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = $rolesArray; // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->IsPasswordReset = 1; // force password reset on first login $UserLogin->IsActive = 1; $UserLogin->scenario = 'create'; $UserLogin->UserRoleID = 1; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; $UserProfile->CompanyID = Yii::app()->user->companyID; $UserProfile->Email = $UserLogin->LoginEmail; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } // save UserProfile $UserProfile->UserLoginID = $UserLogin->UserLoginID; // set newly generated EventID if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } if ($UserProfile->ManagerEmail) { $UserProfilex = UserProfile::model()->findByAttributes(array('Email' => $UserProfile->ManagerEmail)); $candidateModel = new Candidate(); $candidateModel->CompanyID = $UserProfile->CompanyID; $candidateModel->EmployeeID = $UserProfile->EmployeeID; $candidateModel->FirstName = $UserProfile->FirstName; $candidateModel->MiddleName = $UserProfile->MiddleName; $candidateModel->LastName = $UserProfile->LastName; $candidateModel->Title = $UserProfile->Title; $candidateModel->Email = $UserProfile->Email; $candidateModel->CompanyPositionID = 1; $candidateModel->HireDate = date("Y-m-d"); $candidateModel->PositionDate = date("Y-m-d"); $candidateModel->IsActive = 1; $candidateModel->UserProfileID = $UserProfilex->UserProfileID; //$candidateModel->UserProfileId=2; //print_r($candidateModel); // die($UserProfilex->UserProfileID); // if ($candidateModel->validate()) { // if ($candidateModel->save()) { $candidateModel->save(); $performanceModel = new Performance(); $ratingModel = new Rating(); $planningModel = new Planning(); $currentYear = date('Y'); // insert new record $performanceModel->CandidateID = $candidateModel->CandidateID; $performanceModel->PerformanceYear = $currentYear; $ratingModel->CandidateID = $candidateModel->CandidateID; $ratingModel->RatingYear = $currentYear; $planningModel->CandidateID = $candidateModel->CandidateID; $planningModel->PlanningYear = $currentYear; $planningModel->CurrentPositionLevel = 3; $planningModel->NextStepPositionLevel = 3; $planningModel->LongTermPositionLevel = 3; $performanceModel->save(); $ratingModel->save(); $planningModel->save(); //} //} // else //{ // $errores = $candidateModel->getErrors(); // print_r($errores); // die(); // } } // set success message for user Yii::app()->user->setFlash('success', 'A new user was successfully created.'); // return to empty create user form if adding another, else go to user dashboard if (isset($_POST['button-submit-add'])) { $this->redirect($this->createUrl('user/create')); } else { $this->redirect($this->createUrl('user/dashboard')); } } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray)); }
public function test_has_many() { UserLogin::delete_all(); User::delete_all(); $user = new User(); $user->email = "*****@*****.**"; $user->password = "******"; $user->accepted_terms_and_conditions = true; $user->registration_date = new Date(); $user->first_name = "Ben"; $user->last_name = "Copsey"; $user->save(); $user = new User(); $user->email = "*****@*****.**"; $user->password = "******"; $user->accepted_terms_and_conditions = true; $user->registration_date = new Date(); $user->first_name = "Ben"; $user->last_name = "Copsey"; $user->save(); $user = User::find_by_email('*****@*****.**'); $user_login = new UserLogin(); $user_login->user_id = $user->id; $user_login->date = new Date(); $user_login->ip_address = "127.0.0.1"; $user_login->save(); $matches = $user->logins(); FuzzyTest::assert_equal(count($matches), 1, "Should find one login here"); $user_login = new UserLogin(); $user_login->user_id = $user->id; $user_login->date = new Date(); $user_login->ip_address = "127.0.0.1"; $user_login->save(); $matches = UserLogin::find_all_by_user($user); FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here"); $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id)); FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here"); $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 1); FuzzyTest::assert_equal(count($matches), 1, "Should find one login here"); $login = $matches[0]; $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 2); $login2 = $matches[0]; FuzzyTest::assert_equal($login->id, $login2->id, "Two logins should be equal"); $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 0, 2); $login2 = $matches[0]; FuzzyTest::assert_equal($login->id, $login2->id, "Two logins should be equal"); $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 1, 2); $login2 = $matches[0]; FuzzyTest::assert_not_equal($login->id, $login2->id, "Two logins should be equal"); $matches = $user->logins(); FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here"); $login = UserLogin::find_by_user_id($user->id); FuzzyTest::assert_equal($login->user_id, $user->id, "Found wrong login"); $login = UserLogin::find_by_user($user); FuzzyTest::assert_equal($login->user_id, $user->id, "Found wrong login"); $u = User::find_by_login($user_login); FuzzyTest::assert_equal($u->id, $user->id, "Found wrong user"); $user_login = new UserLogin(); $user_login->user = $user; $user_login->date = new Date(); $user_login->ip_address = "127.0.0.1"; $user_login->save(); $matches = $user->logins(); FuzzyTest::assert_equal(count($matches), 3, "Should find three logins here"); $user->delete(); $matches = UserLogin::find_by_user_id($user->id); FuzzyTest::assert_equal(count($matches), 0, "Should find zero logins here"); $matches = UserLogin::find_by_user($user); FuzzyTest::assert_equal(count($matches), 0, "Should find zero logins here"); UserLogin::delete_all(); $user_login1 = new UserLogin(); $user_login1->date = new Date(); $user_login1->ip_address = "127.0.0.1"; $user_login2 = new UserLogin(); $user_login2->date = new Date(); $user_login2->ip_address = "127.0.0.1"; //$user->save(); $user->logins = array($user_login1, $user_login2); $user->save(); $matches = $user->logins; FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here"); $user2 = new User(); $user2 = User::find_by_email('*****@*****.**'); $user_login1->user = $user2; $user_login1->save(); $matches = $user->logins; FuzzyTest::assert_equal(count($matches), 1, "Should find one login here"); $matches = $user2->logins(); FuzzyTest::assert_equal(count($matches), 1, "Should find one login here"); }