public function authenticate() { $record = User::model()->findByAttributes(array('username' => $this->username)); if ($record === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if (!CPasswordHelper::verifyPassword($this->password, $record->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $access = AccessGlobal::getAction($record->role == 'superadmin' ? '0' : '1'); if ($record->role == 'user') { $access['site'] = array_intersect($access['site'], AccessGlobal::getActionFromArrayId(AccessUser::getActionIdFromUser($record->user_id))); } if ($record->role == 'admin') { $access['site'] = array_intersect($access['site'], AccessGlobal::getActionFromArrayId(AccessUser::getActionIdFromUser($record->user_id))); } $this->_id = $record->user_id; $this->setState('role', $record->role); $this->setState('name', $this->username); $this->setState('access', $access); $this->errorCode = self::ERROR_NONE; } } return !$this->errorCode; }
public function actionUserAccessChange() { $user_id = intval($_REQUEST['user_id']); $action_id = intval($_REQUEST['action_id']); if (isset($action_id) and isset($user_id)) { if (AccessUser::checkActionAtUser($user_id, $action_id)) { AccessUser::model()->deleteAllByAttributes(array('user_id' => $user_id, 'action_id' => $action_id)); } else { $access = new AccessUser(); $access->user_id = $user_id; $access->action_id = $action_id; $access->save(); } } $this->redirect($this->createUrl('superadmin/users')); }
public static function checkActionAtUser($user_id, $action_id) { if ($user_id and $action_id) { $res = AccessUser::model()->findAllByAttributes(array('user_id' => $user_id, 'action_id' => $action_id)); return !empty($res); } return false; }
class AccessUser implements IUser { public function insertUser() { var_dump('在accessUser中给user表增加一条记录'); } public function getUser() { var_dump('在accessUser表中根据id得到user表中的一条记录'); } } /* * accessUser 操作user表 */ class AccessDepartment implements IDepartment { public function insertDepartment() { var_dump('在accessUser中给department表增加一条记录'); } public function getDepartment() { var_dump('在accessUser表中根据id得到department表中的一条记录'); } } $userHandle = new SqlserverUser(); $userHandle->insertUser(); $userHandle->insertUser(); $userHandle2 = new AccessUser(); $userHandle2->insertUser(); $userHandle2->insertUser();
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // validate the info, create rules for the inputs $rules = array('user_firstname' => 'required', 'user_gender' => 'required', 'user_joined_date' => 'required|date_format:"' . DATE_FORMAT_2, 'user_left_date' => 'date_format:"' . DATE_FORMAT_2, 'user_email' => 'required|email|unique:user,user_email,' . $id . ',user_key,deleted_at,NULL', 'country_key1' => 'required', 'user_contact_phone_number1' => 'required', 'user_status' => 'required'); // run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules); // if the validator fails, redirect back to the form if ($validator->fails()) { // redirect to list page Session::flash('danger', UNABLE_TO_SAVE); return Redirect::back()->withErrors($validator)->withInput(); } else { // where condition $user = User::userKey($id)->first(); // check if the record can be updated if (empty($user->id)) { // redirect to list page Session::flash('danger', SOMETHING_WENT_WRONG); return Redirect::to(strtolower(USER_TITLE)); } // fields to be updated $user->user_firstname = $this->getInput('user_firstname', ''); $user->user_middlename = $this->getInput('user_middlename', ''); $user->user_lastname = $this->getInput('user_lastname', ''); $user->user_alias = $this->getInput('user_alias', ''); $user->user_gender = $this->getInput('user_gender', ''); $user->user_civil_status = $this->getInput('user_civil_status', ''); $user->user_birth_date = \Carbon\Carbon::createFromFormat(DATE_FORMAT_1, $this->getInput('user_birth_date', DEFAULT_DATE))->format(DB_DATE_FORMAT); $user->user_joined_date = $this->getInput('user_joined_date', ''); $user->user_left_date = $this->getInput('user_left_date', ''); $user->user_email = $this->getInput('user_email', ''); $user->user_hometown_address = $this->getInput('user_hometown_address', ''); $user->user_overseas_address = $this->getInput('user_overseas_address', ''); if (Session::has('user_photo')) { $user->user_photo = Session::get('user_photo'); Session::forget('user_photo'); } $user->user_status = $this->getInput('user_status', ''); $user->updated_by = Auth::user()->id; // update record $user->save(); for ($cnt = 1; $cnt <= $this->getInput('hdn_increment', ''); $cnt++) { if ($this->getInput('hdn_index' . $cnt, '') == YES && $this->getInput('country_key' . $cnt, '') != EMPTY_STRING && $this->getInput('user_contact_phone_number' . $cnt, '') != EMPTY_STRING) { if ($this->getInput('user_contact_key' . $cnt, '') == EMPTY_STRING) { $data = array(); $data['user_contact_key'] = generateRandomID(); $data['user_id'] = $user->id; $data['country_id'] = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id'); $data['user_contact_phone_number'] = $this->getInput('user_contact_phone_number' . $cnt, ''); $data['created_by'] = Auth::user()->id; // create record UserContact::create($data); } else { // where condition $user_contact = UserContact::UserContactKey($this->getInput('user_contact_key' . $cnt, ''))->first(); // check if the record can be updated if (isset($user_contact->id)) { $user_contact->country_id = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id'); $user_contact->user_contact_phone_number = $this->getInput('user_contact_phone_number' . $cnt, ''); $user_contact->updated_by = Auth::user()->id; // update record $user_contact->save(); } } } } // where condition $user_emergency = UserEmergency::userId($user->id)->first(); // check if the record can be updated if (!empty($user_emergency->id)) { // fields to be updated $user_emergency->user_emergency_name = $this->getInput('user_emergency_name', ''); $user_emergency->user_emergency_relation = $this->getInput('user_emergency_relation', ''); $user_emergency->user_emergency_address = $this->getInput('user_emergency_address', ''); $user_emergency->country_id = Country::countryKey($this->getInput('emergency_country_key', ''))->pluck('id'); $user_emergency->user_emergency_phone = $this->getInput('user_emergency_phone', ''); $user_emergency->updated_by = Auth::user()->id; // update record $user_emergency->save(); } // flag all approver template records AccessUser::userId($user->id)->update(array('access_user_flag' => YES)); // create access record if (is_array($this->getInput('access_user', array()))) { foreach ($this->getInput('access_user', array()) as $access_id) { $access_user = AccessUser::accessId($access_id)->userId($user->id)->first(); if (isset($access_user->id) && !empty($access_user->id)) { // update record $access_user->user_id = $user->id; $access_user->access_id = $access_id; $access_user->access_user_flag = NO; $access_user->updated_by = Auth::user()->id; $access_user->save(); } else { // create record $data = array(); $data['user_id'] = $user->id; $data['access_id'] = $access_id; $data['access_user_flag'] = NO; $data['created_by'] = Auth::user()->id; AccessUser::create($data); } } // delete records set to yes AccessUser::AccessUserFlag(YES)->UserId($user->id)->delete(); } // redirect to list page Session::flash('success', SUCCESS_UPDATE); return Redirect::to($this->getPreviousListURL()); } }
?> <tr> <td><?php echo $user->username; ?> </td> <td class ="<?php echo $user->role == 'admin' ? 'EnableTD' : 'DisableTD'; ?> "><?php echo ucfirst($user->role); ?> </td> <?php foreach ($actions as $action) { $check = AccessUser::checkActionAtUser($user->user_id, $action->id); ?> <td class ="<?php echo $check ? 'EnableTD' : 'DisableTD'; ?> "> <?php echo CHtml::link($check ? 'On' : 'Off', array('admin/useraccesschange', 'user_id' => $user->user_id, 'action_id' => $action->id)); ?> </td> <?php } ?> <td> <?php