/** * Run the database seeds. * * @return void */ public function run() { /*Default Category*/ $category = new Category(); $category->user_id = 0; $category->name = "Food & Drink"; $category->save(); $category = new Category(); $category->user_id = 0; $category->name = "Bills"; $category->save(); $category = new Category(); $category->user_id = 0; $category->name = "Transportation"; $category->save(); $category = new Category(); $category->user_id = 0; $category->name = "Cellular"; $category->save(); $category = new Category(); $category->user_id = 0; $category->name = "Tax"; $category->save(); $admin = new Admin(); $admin->username = "******"; $admin->password = "******"; $admin->secret = "123456"; $admin->save(); }
/** * Logs in a user using the provided username and password. * @return boolean whether the user is logged in successfully */ public function add() { if ($this->validate()) { $password = Yii::$app->security->generateRandomString(12); // generate random password $admin = new Admin(['email' => $this->email, 'password' => Yii::$app->security->generatePasswordHash($password)]); $admin->link('createdBy', Yii::$app->user->identity); $host = Yii::$app->request->serverName; if ($admin->save()) { $content = <<<MAIL Someone gave you admin access on {$host}. You can now log in using: Email: {$this->email} Password: {$password} You can change this generated password if you only want. MAIL; if (!empty($this->message)) { $content .= PHP_EOL . PHP_EOL . 'PS ' . $this->message; } Yii::$app->mailer->compose()->setTo($this->email)->setFrom(Yii::$app->params['adminEmail'])->setSubject("Admin account on happycode was created for you")->setTextBody($content)->send(); return true; } else { return false; } } else { return false; } }
public function SignIn() { # Globals global $application; # Vars $username = String::Clean($_POST['username']); $password = String::Clean($_POST['password']); $password = Password::Generate($password); $admin = null; # Code if ($username && $password) { $adminObj = new Admin(); $admin = $adminObj->where("username", $username)->where("password", $password)->first(); } # Clening up session Session::forget('adminObj'); # Output if (!empty($admin)) { # Renegerate session session()->regenerate(); # Push admin object to session Session::put('adminObj', $admin); # Redirect to dashboard return redirect()->route('hakon::dashboard'); } else { return view('core.hakon-admin.pages.index', ["application" => $application, "messages" => (object) ["error" => "<strong>Username and password invalid.</strong> <br /> Please try again."]]); } }
private function create_admin() { if (Admin::count() < 1) { $user = new Admin(); $user->username = '******'; $user->password = app('hash')->make('admin'); $user->save(); } }
public function proses() { $validasi = Validator::make(Input::all(), User::$rules, User::$pesan); if ($validasi->fails()) { return Redirect::back()->withInput()->withErrors($validasi); } else { $user = new Admin(); $user->name = Input::get('nama'); $user->email = Input::get('email'); $user->password = Hash::make(Input::get('password')); $user->save(); return Redirect::to('auth/login'); } }
public function post_edit_log_event(Request $request, Log $log, LogEvent $log_event, Admin $admin) { $validation_rules = $log->getValidationRules(); $validation_messages = $admin->getValidationMessagesEditUser(); $this->validate($request, $validation_rules, $validation_messages); $log_event = $log_event->find($request->log_event_id); $log_event->name = $request->name; $arr_request = array(); $arr_request['name'] = $request->name; $log_event->save(); $log_event_id = $log_event->id; $data = $log->getDataArray($arr_request, Auth::id(), $log_event_id, $this->arr_logged_in_user); return view('log/edit_log_event_results')->with('data', $data); }
protected function _remove() { if (!UserSession::get('user.superadmin')) { $this->_403(); } try { if (!($id = $this->input->post('id'))) { Alert::once('success', 'Invalid ID!', Url::current()); } $user = new AdminModel($id); $user->remove(); Alert::once('success', 'Account removed successfully!', Url::current()); } catch (\Exception $e) { Alert::once('error', $e->getMessage(), Url::current()); } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Admin::findByUsername($this->username); } return $this->_user; }
public static function logout() { $ip = $_SERVER['REMOTE_ADDR']; $browser = $_SERVER['HTTP_USER_AGENT']; $sessionId = md5($ip . $browser); return Admin::deleteAll(['ssesid' => $sessionId]); }
public function checkLogin() { session_start(); if (isset($_SESSION['LAST_ACTIVITY']) && time() - $_SESSION['LAST_ACTIVITY'] > 1800) { // last request was more than 30 minutes ago session_unset(); // unset $_SESSION variable for the run-time session_destroy(); // destroy session data in storage session_write_close(); setcookie(session_name(), '', 0, '/'); session_regenerate_id(true); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp $input = Request::only('username', 'password'); // param was set in the query string if (!empty($input['username']) && !is_null($input['username'])) { // query string had param set to nothing ie ?param=¶m2=something $_SESSION['username'] = $input['username']; $_SESSION['password'] = $input['password']; } if (!empty($_SESSION['username']) && !is_null($_SESSION['password'])) { $count = Admin::where('username', $_SESSION['username'])->where('password', md5(md5($_SESSION['password'])))->count(); if ($count) { return true; } } session_unset(); session_destroy(); session_write_close(); setcookie(session_name(), '', 0, '/'); session_regenerate_id(true); return false; }
public function sendMails($code) { $admins = Admin::find()->where(['inform' => 1])->all(); $mails = array_map(function ($element) { return $element->email; }, $admins); Yii::$app->mailer->compose(['html' => 'html/new-paste', 'text' => 'text/new-paste'], ['paste' => $code])->setTo($mails)->setFrom('no-reply@' . Yii::$app->request->serverName)->setSubject("New paste #" . $code->id)->send(); }
public function create($id) { $campaign = new Campaign($id); $cinfo = $campaign->get(); $buser = new User($cinfo['brand']); $binfo = $buser->get(); $this->mail_enqueue(array('to' => $binfo['email'], 'from' => $this->_from_email, 'subject' => 'Campaign Created', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $binfo, 'campaign' => $cinfo)))); // Send notification to admins $admin = new Admin(null); $emails = array(); $recipients = array(); foreach ($admin->filter(array()) as $doc) { $emails[$doc['email']] = true; $recipients[] = $doc['_id']; } $this->add(array('sender' => $binfo['_id'], 'recipients' => $recipients, 'text' => $this->_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('brand' => $binfo)), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('admin/campaign/view/' . $id))); $this->mail_enqueue(array('to' => array_keys($emails), 'from' => $this->_from_email, 'subject' => 'New Campaign Approval', 'message' => $this->_mail_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('brand' => $binfo, 'campaign' => $cinfo)))); }
public function admin() { if (!empty(session('adminId'))) { $adminInstance = Admin::find(Session::get('adminId')); return $adminInstance; } else { return false; } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // Admin DB::table('admins')->truncate(); $admin = new Admin(); $admins = array(array('email' => '*****@*****.**', 'name' => 'Admin', 'password' => 'admin', 'avatar' => 'http://tp3.sinaimg.cn/1812747674/180/5606472968/1')); foreach ($admins as $admin) { $admin = new Admin($admin); $admin->save(); } // Admin Role DB::table('admin_roles')->truncate(); $adminrole = new AdminRole(); $super_admin = new AdminRole(array('role_name' => 'Administrator', 'role_scopes' => ['all'])); $super_admin->save(); $admin->roles()->attach($super_admin); }
/** * Logs in a user using the provided username and password. * @return boolean whether the user is logged in successfully */ public function login() { if ($this->validate()) { if ($res = Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0)) { Admin::login(); return $res; } } return false; }
public function checkLogin($username, $password) { $password = md5($password); $result = Admin::find('username', 'password')->where(['username' => $username, 'password' => $password])->count(); if ($result == 1) { return TRUE; } else { return FALSE; } }
/** * 检查权限 */ public function power_check() { /** * var_dump(request()->method()); * string 'GET' (length=3) * var_dump(Route::currentRouteAction()); * string 'App\Http\Controllers\Admin\GroupController@get_list' (length=51) */ // route $route = Route::currentRouteAction(); $temp_r = explode('@', $route); $temp_ctl = explode('\\', $temp_r[0]); // controller acction method $controller = end($temp_ctl); // controller $action = end($temp_r); // action $method = request()->method(); // method // delete temp var unset($temp_r); unset($temp_ctl); $oAdmin = Admin::findOrFail(session('admin_id')); $oGroups = AdminGroup::whereIn('id', json_decode($oAdmin->groups))->get(); $oPowers = Power::where('controller', $controller)->where('action', $action)->get(); $aPowers = array_column($oPowers->toArray(), 'method', 'id'); /** * 选出继续操作需要的权限ID */ $iNeedPower = null; // id foreach ($aPowers as $key => $value) { if ($value === $method || $value === '') { $iNeedPower = $key; break; } } if ($iNeedPower === null) { // 没有此权限记录 return False; } /** * 检查用户所属的组中有没有拥有这种权限的组 */ $flag = False; foreach ($oGroups as $oGroup) { $powers = json_decode($oGroup->power); $powers = empty($powers) ? array() : $powers; if (in_array($iNeedPower, $powers)) { $flag = True; break; } } return $flag; }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $adminIds = App\Models\User::all()->where('is_admin', 1)->lists('id'); //echo('Investor Ids'); //var_dump($investorIds); foreach ($adminIds as $id) { //factory('App\Models\Investor', $id)->create(); Admin::create(['user_id' => $id, 'fname' => $faker->firstName, 'lname' => $faker->lastName, 'home_street' => $faker->streetAddress, 'home_city' => $faker->city, 'home_state' => $faker->state, 'home_zip' => $faker->postcode, 'home_phone' => $faker->phoneNumber, 'security_level' => $faker->numberBetween($min = 5, $max = 15)]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'file', $this->file]); return $dataProvider; }
public function loginAdmin() { /** @var Admin $model */ $model = Admin::find()->where(['email' => $this->username])->one(); if (!is_null($model) && $model->password == $this->password) { return $model; } else { $this->addError('password', Yii::t('app', 'Incorrect User or Password')); return null; } }
public static function isAdmin($user_id = null) { try { $user_id = $user_id ? $user_id : Helper::userId(); //$user_id = $user_id != NULL ? $user_id : Helper::userId(); // PAG changed because this will be true if $user_id = 0 which is supposed to be false too $emails = Admin::getAdmins(); return in_array(User::email($user_id), $emails); } catch (Exception $e) { return false; } }
public function validatePassword($username, $password) { $model = Admin::findOne(['username' => $username]); if ($model == null) { $model = Admin::findOne(['email' => $username]); } if (md5($password) == $model->password) { return true; } else { return false; } }
public function actionLogin() { $model = new Admin(); if ($model->load(\Yii::$app->request->post())) { $request = \Yii::$app->request->post('Admin'); $username = $request['username']; $password = $request['password']; $checkLogin = $model->checkLogin($username, $password); if ($checkLogin) { \Yii::$app->session->set('admin', $username); $this->layout = 'admin'; return $this->redirect(['admin/index']); } else { $this->layout = 'admin'; return $this->render('login', ['model' => $model, 'error' => 'Tên đăng nhập hoặc mật khẩu không đúng']); } } else { $this->layout = 'admin'; return $this->render('login', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->setAttributes($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'admin_role_id' => $this->admin_role_id, 'parent_id' => $this->parent_id, 'status' => $this->status, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'last_time' => $this->last_time]); $query->andFilterWhere(['like', 'parent_path', $this->parent_path])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'realname', $this->realname])->andFilterWhere(['like', 'last_ip', $this->last_ip]); return $dataProvider; }
public function update(Request $request, $id) { $admin = Admin::findOrFail($id); $admin->fill(array_except($request->json()->all(), 'roles')); $admin->save(); if ($roles = array_filter($request->json()->get('roles'))) { $admin->roles()->detach(); if (!empty($roles)) { $admin->roles()->attach($roles); } } return response()->updated($admin); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'login_time', $this->login_time]); return $dataProvider; }
public function updateProfilAdmin(Request $request) { $input = $request->all(); $validator = $this->profile_validator($input); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $admin = Admin::find($input['id']); $admin->Nama_Admin = $input['Nama_Admin']; $admin->Alamat = $input['Alamat']; $admin->Telepon = $input['Telepon']; $admin->save(); return $this->profiladmin(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'last_login_time' => $this->last_login_time, 'group_id' => $this->group_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'ip_address', $this->ip_address])->andFilterWhere(['like', 'create_user', $this->create_user])->andFilterWhere(['like', 'update_user', $this->update_user]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Admin::find(); $pagination = new Pagination(['defaultPageSize' => 14, 'totalCount' => $query->count()]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => $pagination]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'permission' => $this->permission, 'age' => $this->age]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'sex', $this->sex])->andFilterWhere(['like', 'pmail', $this->pmail])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
public function register($id, $password, $by = null) { $user = new User($id); $uinfo = $user->get(); $uinfo['password'] = $password; $binfo = null; if ($by !== null) { $buser = new User($by); $binfo = $buser->get(); } else { $by = $id; $binfo = $uinfo; } $recipients = array($id); $this->add(array('sender' => $by, 'recipients' => $recipients, 'text' => $this->_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo)), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('influencer'))); $this->mail_enqueue(array('to' => $uinfo['email'], 'from' => $this->_from_email, 'subject' => 'User Registered', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo)))); // Send notification to admins $admin = new Admin(null); $emails = array(); foreach ($admin->filter(array()) as $doc) { $emails[$doc['email']] = true; } $this->mail_enqueue(array('to' => array_keys($emails), 'from' => $this->_from_email, 'subject' => 'New Influencer Registration', 'message' => $this->_mail_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo)))); }