/** * Store a newly created user in storage. * * @return Response */ public function store() { if (!Sentry::getUser()) { return Redirect::route('sessions.create'); } $validator = Validator::make($data = Input::all(), User::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } try { // Create the user $user = Sentry::createUser(array('email' => $data['email'], 'password' => $data['password'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'phone' => $data['phone'], 'activated' => true)); // Find the group using the group id $group = Sentry::findGroupById($data['group']); // Assign the group to the user $user->addGroup($group); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { echo 'User with this login already exists.'; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group was not found.'; } return Redirect::route('users.index'); }
public function store() { $v = Validator::make($data = Input::all(), User::$rules); if ($v->fails()) { return Response::json(array($v->errors()->toArray()), 500); // return Response::json(array('flash' => 'Something went wrong, try again !'), 500); } else { $user = Sentry::register(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')), true); if (Input::hasFile('picture')) { $uploaded_picture = Input::file('picture'); // mengambil extension file $extension = $uploaded_picture->getClientOriginalExtension(); // membuat nama file random dengan extension $filename = md5(time()) . '.' . $extension; $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img/photos'; // memindahkan file ke folder public/img/photos $uploaded_picture->move($destinationPath, $filename); // mengisi field picture di user dengan filename yang baru dibuat $user->picture = $filename; $user->save(); } // Find the similiar group $GroupId = Sentry::findGroupById(Input::get('group_id')); // Insert user user into specified group $user->addGroup($GroupId); return Response::json(array('flash' => 'New user has been successfully created !'), 200); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|min:4|max:254|email', 'password' => 'required|min:6|confirmed', 'password_confirmation' => 'required', 'group' => 'required'); $validator = Validator::make($input, $rules); if ($validator->passes()) { $result = array(); try { $user = \Sentry::register(array('email' => $input['email'], 'password' => $input['password'], 'first_name' => $input['first_name'], 'last_name' => $input['last_name'])); $group = \Sentry::findGroupById($input['group']); $user->addGroup($group); $this->mailer->welcome($user); $result['success'] = true; $result['message'] = 'Activation code is sent , please check your email'; } catch (Exception\LoginRequiredException $e) { $result['success'] = false; $result['message'] = 'Login field is required.'; } catch (Exception\PasswordRequiredException $e) { $result['success'] = false; $result['message'] = 'Password field is required.'; } catch (Exception\UserExistsException $e) { $result['success'] = false; $result['message'] = 'User with this login already exists'; } return Redirect::route('users.index')->with('message', $result['message']); //return Redirect::route('users.index')->with('message','Successfully Registered'); } return Redirect::route('users.create')->withInput()->withErrors($validator); }
public function save() { if (Request::ajax() && Request::isMethod('post')) { try { $input = Input::all(); $valid = Validator::make($input, ['username' => 'required', 'email' => 'required|email', 'full_name' => 'required']); if ($valid->fails()) { throw new Exception('Todos los campos son obligatorios'); } if (empty($input['id'])) { $group = Sentry::findGroupById($input['group']); $user = Sentry::createUser(['username' => $input['username'], 'email' => $input['email'], 'full_name' => $input['full_name'], 'password' => $input['password_confirmation'], 'activated' => !empty($input['activated']) ? 1 : 0]); $user->addGroup($group); } else { $user = Sentry::findUserById($input['id']); $user->email = $input['email']; $user->full_name = $input['full_name']; $user->activated = !empty($input['activated']) ? 1 : 0; $user->save(); } return Response::json(URL::route('admin.users'), 200); } catch (Exception $e) { return Response::json($e->getMessage(), 400); } } }
public function update($id) { try { // Find the user using the user id $user = Sentry::findUserById($id); $user->last_name = Input::get('last_name'); $user->activated = Input::get('activated'); // Update the user if ($user->save()) { $userGroups = $user->groups()->lists('group_id'); $selectedGroups = array(Input::get('group')); $groupsToAdd = array_diff($selectedGroups, $userGroups); $groupsToRemove = array_diff($userGroups, $selectedGroups); foreach ($groupsToAdd as $groupId) { $group = Sentry::findGroupById($groupId); $user->addGroup($group); } foreach ($groupsToRemove as $groupId) { $group = Sentry::findGroupById($groupId); $user->removeGroup($group); } // User information was updated } else { // User information was not updated } return Redirect::route('admin.users.index'); } catch (Cartalyst\Sentry\Users\UserExistsException $e) { return Redirect::back()->withInput()->withErrors('User with this login already exists.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::back()->withInput()->withErrors('User was not found.'); } }
public function postDenegarpermiso($idgrupo, $permiso) { $sentryGroups = \Sentry::findGroupById($idgrupo); $permisos = $sentryGroups->getPermissions(); $permisos[$permiso] = 0; $sentryGroups->permissions = $permisos; $sentryGroups->save(); return \Response::json(array('mensaje' => 'Se denego el permiso correctamente.')); }
public static function permissions($id, $name_permissions) { $group = Sentry::findGroupById($id); foreach ($group->getPermissions() as $name => $activated) { if ($name_permissions == $name && $activated == 1) { return True; } } }
public function testRetrieveGroupByName() { // Find the group we will use for reference $reference = Sentry::findGroupById(1); // This is the code we are testing $group = $this->repo->retrieveByName($reference->name); // Assertions $this->assertInstanceOf('Sentinel\\Models\\Group', $group); $this->assertEquals(1, $group->id); }
public function destroy($id) { try { $group = Sentry::findGroupById($id); $group->delete(); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group was not found.'; } return Redirect::route('admin.group.index')->with("successMessage", "Data berhasil dihapus "); }
/** * Run the database seeds. * * @return void */ public function run() { //创建用户组 Sentry::createGroup(array('name' => 'Admin', 'is_admin' => 1, 'permissions' => [])); Sentry::createGroup(array('name' => 'Guest', 'is_admin' => 0, 'permissions' => [])); $user = Sentry::createUser(array('email' => '*****@*****.**', 'username' => 'admin', 'password' => '123456', 'activated' => true)); $adminGroup = Sentry::findGroupById(1); $user->addGroup($adminGroup); Uinfo::create(['uid' => $user->id]); }
public function run() { DB::table('users')->delete(); DB::table('groups')->delete(); DB::table('users_groups')->delete(); $user = Sentry::createUser(array('username' => 'superadmin', 'password' => 'ad123min', 'first_name' => 'Super', 'last_name' => 'Administrator', 'activated' => 1)); $group = Sentry::createGroup(array('name' => 'Super Administrators', 'permissions' => array('superuser' => 1))); // Assign user permissions $userGroup = Sentry::findGroupById(1); $user->addGroup($userGroup); }
/** * Create new random superuser. * * @param string $password * * @return \VisualAppeal\Connect\User */ protected function createSuperuser($password = '******') { $lastLogin = $this->faker->dateTime(); $admin = \Sentry::createUser(['email' => $this->faker->email, 'password' => $password, 'activated' => 1, 'activated_at' => $this->faker->dateTime($lastLogin), 'last_login' => $lastLogin, 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName]); try { $adminGroup = Sentry::findGroupById(1); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { $adminGroup = Sentry::createGroup(['name' => 'Superuser', 'permissions' => ['superuser' => 1]]); } $admin->addGroup($adminGroup); return $admin; }
/** * Admin.group.update */ public function postUpdate($id = null) { // Set permission Auth::requirePermissions('admin.group.update'); try { if (empty($id)) { $id = \Input::get('id'); } // Find the user using the group id $group = \Sentry::findGroupById($id); $permissions_save = \Input::get('btn_save_permissions'); if (empty($permissions_save)) { // Update group if ($id > 2) { $group->name = \Input::get('name'); } $group->save(); } else { if ($group->id > 2) { // Update permissions $permission_data = \Input::get(); $permissions = array(); // Unset previous permissions $group_permissions = $group->getPermissions(); foreach ($group_permissions as $p => $value) { $permissions[$p] = 0; } // Add new ones foreach ($permission_data as $p => $value) { // Skip extra information if ($p == 'id' || $p == 'btn_save_permissions') { continue; } // Form undo transform $p = str_replace('_', '.', $p); // Permission set $permissions[$p] = 1; } // Save permissions $group->permissions = $permissions; $group->save(); } } } catch (\Cartalyst\Sentry\Groups\NameRequiredException $e) { Flash::set('Name is required'); } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) { // Ignore and redirect back } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) { // Ignore and redirect back } return \Redirect::to('api/admin/groups'); }
/** * Run the migrations. * * @return void */ public function up() { /*create the first user as super admin*/ $user = Sentry::createUser(array('email' => '*****@*****.**', 'password' => 'test1234', 'activated' => true, 'first_name' => 'Amitav', 'last_name' => 'Roy')); $group = Sentry::createGroup(array('name' => 'Super Admin', 'permissions' => array('create_users' => 1, 'edit_users' => 1, 'delete_users' => 1, 'manage_users' => 1, 'manage_permissions' => 1))); $adminGroup = Sentry::findGroupById(1); $user->addGroup($adminGroup); /*create second user as admin*/ $user = Sentry::createUser(array('email' => '*****@*****.**', 'password' => 'test1234', 'activated' => true, 'first_name' => 'Jhon', 'last_name' => 'Doe')); $group = Sentry::createGroup(array('name' => 'Administrator', 'permissions' => array('create_users' => 1, 'edit_users' => 1, 'delete_users' => 0, 'manage_users' => 0, 'manage_permissions' => 0))); $adminGroup = Sentry::findGroupById(2); $user->addGroup($adminGroup); $group = Sentry::createGroup(array('name' => 'Authenticated User')); }
public function create_post() { $validator = Validator::make(Input::all(), User::get_rules()); if ($validator->fails()) { return Redirect::to('admin/clients/create')->withErrors($validator)->withInput(); } else { $user = Sentry::createUser(array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'tin_number' => Input::get('tin_number'), 'landline' => Input::get('landline'), 'mobile' => Input::get('mobile'), 'work_address' => json_endcode(explode(",", Input::get('work_address'))), 'home_address' => json_endcode(explode(",", Input::get('home_address'))), 'company' => Input::get('company'), 'occupation' => Input::get('occupation'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'activated' => true)); // Find the group using the group id $group = Sentry::findGroupById(1); // Assign the group to the user $user->addGroup($group); return Redirect::to('admin/clients')->with('success', 'Client account has been successfully created.'); } }
/** * This is an internal function to check if the user has the permission. * @param $permissionName * @return bool */ public static function user_has_permission($permissionName) { $user = Sentry::getUser(); $superAdmin = Sentry::findGroupById(1); // hard coded to get super admin // check if super admin, bypass has access check if ($user->inGroup($superAdmin)) { return true; } if ($user->hasAccess($permissionName)) { return true; } else { return false; } }
/** * Store a newly registered member * * @return response **/ public function postRegister() { $validator = Validator::make(Input::all(), array('first_name' => 'required|min:2', 'last_name' => 'required|min:2', 'membership_no' => 'required', 'email' => 'required|email|max:50|unique:users', 'password' => 'required|min:6', 'confirm_password' => 'required|same:password')); if ($validator->fails()) { return Redirect::route('account-register')->withErrors($validator)->withInput(); } else { try { $user = Sentry::createUser(array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'membership_no' => Input::get('membership_no'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'activated' => true)); if ($user) { $userGroup = Sentry::findGroupById(2); $user->addGroup($userGroup); return Redirect::route('home')->with('global', 'A new ' . $userGroup->name . ' has been created!'); } } catch (\Exception $e) { return Redirect('account-register')->with('error', $e->getMessage()); } } }
/** * admin.groups.update * */ public function putAdminUpdate($id) { if (Sentry::hasAnyAccess(['groups_update'])) { try { $group = Sentry::findGroupById($id); $group->name = Input::get('name'); $group->permissions = ['admin' => Input::get('admin'), 'deeds_index' => Input::get('deeds_index'), 'deeds_create' => Input::get('deeds_create'), 'deeds_update' => Input::get('deeds_update'), 'deeds_delete' => Input::get('deeds_delete'), 'agrarians_index' => Input::get('agrarians_index'), 'agrarians_create' => Input::get('agrarians_create'), 'agrarians_update' => Input::get('agrarians_update'), 'agrarians_delete' => Input::get('agrarians_delete'), 'civils_index' => Input::get('civils_index'), 'civils_create' => Input::get('civils_create'), 'civils_update' => Input::get('civils_update'), 'civils_delete' => Input::get('civils_delete'), 'penals_index' => Input::get('penals_index'), 'penals_create' => Input::get('penals_create'), 'penals_update' => Input::get('penals_update'), 'penals_delete' => Input::get('penals_delete'), 'records_index' => Input::get('records_index'), 'records_create' => Input::get('records_create'), 'records_update' => Input::get('records_update'), 'records_delete' => Input::get('records_delete'), 'notaries_index' => Input::get('notaries_index'), 'notaries_create' => Input::get('notaries_create'), 'notaries_update' => Input::get('notaries_update'), 'notaries_delete' => Input::get('notaries_delete'), 'municipalities_index' => Input::get('municipalities_index'), 'municipalities_create' => Input::get('municipalities_create'), 'municipalities_update' => Input::get('municipalities_update'), 'municipalities_delete' => Input::get('municipalities_delete'), 'users_index' => Input::get('users_index'), 'users_create' => Input::get('users_create'), 'users_update' => Input::get('users_update'), 'users_delete' => Input::get('users_delete'), 'groups_index' => Input::get('groups_index'), 'groups_create' => Input::get('groups_create'), 'groups_update' => Input::get('groups_update'), 'groups_delete' => Input::get('groups_delete')]; $group->save(); return Redirect::route('admin.groups.edit', $id)->with(['message' => 'El grupo fue actualizado con exito!', 'class' => 'success']); } catch (Cartalyst\Sentry\Groups\NameRequiredException $e) { return Redirect::route('admin.groups.edit', $id)->with(['message' => 'El nombre es requerido', 'class' => 'warning']); } catch (Cartalyst\Sentry\Groups\GroupExistsException $e) { return Redirect::route('admin.groups.edit', $id)->with(['message' => 'El grupo ya existe', 'class' => 'warning']); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { return Redirect::route('admin.groups.edit', $id)->with(['message' => 'El grupo no fue encontrado.', 'class' => 'danger']); } } else { return Redirect::route('pages.error'); } }
/** * Store a newly created karyawan in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Karyawan::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } // Register User tanpa diaktivasi $user = Sentry::register(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'nip' => Input::get('nip'), 'unit_kerja' => Input::get('unit_kerja'), 'unit' => Input::get('unit'), 'jabatan' => Input::get('jabatan')), false); // Cari grup regular $regularGroup = Sentry::findGroupById(Input::get('group')); // Masukkan user ke grup regular $user->addGroup($regularGroup); // Persiapkan activation code untuk dikirim ke email $data = ['email' => $user->email, 'activationCode' => $user->getActivationCode()]; // Kirim email aktivasi Mail::send('emails.auth.register', $data, function ($message) use($user) { $message->to($user->email, $user->first_name . ' ' . $user->last_name)->subject('Aktivasi Akun SIM Kinerja LPPM UNESA'); }); // Redirect ke halaman login return Redirect::route('admin.karyawan.index')->with("successMessage", "Berhasil disimpan. Silahkan cek email ({$user->email}) untuk melakukan aktivasi akun."); }
/** * Store a newly created resource in storage. * POST /user * * @return Response */ public function store() { // try { // Create the user $user = Sentry::createUser(array('email' => Input::get('username'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'activated' => true)); // Find the group using the group id $adminGroup = Sentry::findGroupById(1); // Assign the group to the user $user->addGroup($adminGroup); return View::make('users.create')->with('groups', DB::table('groups')->lists('name', 'id'))->with('companies', DB::table('users_companies')->lists('name', 'id')); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { echo 'User with this login already exists.'; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group was not found.'; } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { try { $user = Sentry::createUser(array('email' => Input::get('email'), 'password' => (string) Input::get('password'), 'activated' => Input::get('activated') == 'activated' ? 1 : 0, 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'))); if ($user->id) { Session::flash('message', trans('kuu-validation.user_create_successfully')); $groups_arr = Input::get('groups'); foreach ($groups_arr as $group_id) { $group = Sentry::findGroupById($group_id); $user->addGroup($group); } } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('error_message', trans('kuu-validation.login_field_is_required')); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { Session::flash('error_message', trans('kuu-validation.password_field_is_required')); } catch (Cartalyst\Sentry\Users\UserExistsException $e) { Session::flash('error_message', trans('kuu-validation.user_with_this_login_already_exists')); } //return Redirect::to('/admin/user'); return Redirect::route('admin.user', array('lang' => App::getLocale())); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { // Find the user $user = Sentry::findUserById($id); $rules = User::$updateRules; $rules['email'] = 'required|unique:users,id,' . $id; if (Input::get('password')) { $rules['password'] = '******'; } $validator = Validator::make(Input::all(), $rules); if ($validator->passes()) { $group = Sentry::findGroupById(Input::get('role')); $outlet_id = Input::get('outlet_id') == 'all' || Input::get('outlet_id') == 0 ? 0 : Input::get('outlet_id'); $user->email = Input::get('email'); if (Input::get('password')) { $user->password = Input::get('password'); } $user->name = Input::get('name'); $user->phone = Input::get('phone'); $user->address = Input::get('address'); $user->outlet_id = $outlet_id; $user->activated = Input::get('activated'); $user->save(); // Remove existing group $userGroups = $user->getGroups(); foreach ($userGroups as $usergroup) { $user->removeGroup($usergroup); } // Assign the group to the user $user->addGroup($group); return Redirect::route('users.edit', $id)->with('success', 'User updated successfully'); } else { return Redirect::route('users.edit', $id)->withErrors($validator)->withInput(Input::all()); } }
public function storeUser() { $this->layout->title = APPNAME; if (Input::has('sid') && Input::has('email') && Input::has('pass') && !Input::has('edit-field') && strlen(Input::get('sid')) == 9) { $sid = Input::get('sid'); $email = Input::get('email'); $pass = Input::get('pass'); $fname = Input::get('fname'); $lname = Input::get('lname'); try { // Create the user $user = Sentry::createUser(array('student_id' => $sid, 'email' => $email, 'password' => $pass, 'activated' => true, 'first_name' => $fname, 'last_name' => $lname)); $permissions = Input::get('permissions'); foreach ($permissions as $id => $permission) { if ($permission == "on") { $group = Sentry::findGroupById($id); $user->addGroup($group); } } if ($user->save()) { // User information was updated } else { // User information was not updated } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { echo 'User with this login already exists.'; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group was not found.'; } $users = Sentry::findAllUsers(); $this->layout->content = View::make('main.admin.users')->with('users', $users); } elseif (Input::has('edit-field')) { $eid = Input::get('edit-field'); $user = Sentry::findUserById($eid); $sid = Input::get('sid'); $email = Input::get('email'); $pass = Input::get('pass'); $fname = Input::get('fname'); $lname = Input::get('lname'); $user->student_id = $sid; $user->email = $email; $user->password = $pass; $user->first_name = $fname; $user->last_name = $lname; $permissions = Input::get('permissions'); $grps = Sentry::findAllGroups(); foreach ($grps as $grp) { $user->removeGroup($grp); } foreach ($permissions as $id => $permission) { if ($permission == "on") { $group = Sentry::findGroupById($id); $user->addGroup($group); } } if ($user->save()) { // User information was updated } else { // User information was not updated } $users = Sentry::findAllUsers(); $this->layout->content = View::make('main.admin.users')->with('users', $users); } elseif (Input::has('delid')) { $eid = Input::get('delid'); $user = Sentry::findUserById($eid); $user->delete(); $users = Sentry::findAllUsers(); $this->layout->content = View::make('main.admin.users')->with('users', $users); } }
public function handleDeleteRow($id) { $group = \Sentry::findGroupById($id); $group->delete(); return array('id' => $id, 'status' => true); }
function postUpdate($id = 0, &$data) { // check validate $username = trim(Input::get('username')); $password = trim(Input::get('password')); $groupID = Input::get('group'); $UpdateRules = $this->model->getUpdateRules(); if ($id != 0) { if (empty($password)) { unset($UpdateRules['password']); } } $validate = Validator::make(Input::all(), $UpdateRules, $this->model->getUpdateLangs()); if ($validate->passes()) { if ($id == 0) { // INSERT try { $user = Sentry::createUser(array('username' => $username, 'password' => $password, 'activated' => TRUE)); if ($groupID != 0 && is_numeric($groupID)) { $groupItem = Sentry::findGroupById($groupID); $permissions = $groupItem->getPermissions(); // dump_exit($permissions); $user->addGroup($groupItem); $user->permissions = $permissions; $user->save(); } $data['id'] = $user->id; return TRUE; } catch (\Cartalyst\Sentry\Users\UserExistsException $e) { $data['message'] = 'Tên đăng nhập đã tồn tại. Vui lòng nhập tên đăng nhập khác'; } } else { // UPDATE try { $userData = Sentry::findUserById($id); $userData->username = $username; $oldGroup = $userData->getGroups()->first(); if (!empty($password)) { $userData->password = $password; } if ($userData->save()) { if ($oldGroup != NULL) { if ($groupID != $oldGroup->id) { $userData->removeGroup($oldGroup); if ($groupID != 0 && is_numeric($groupID)) { $newGroup = Sentry::findGroupById($groupID); $permissions = $newGroup->getPermissions(); $userData->addGroup($newGroup); $userData->permissions = $permissions; $userData->save(); } } } else { if ($groupID != 0 && is_numeric($groupID)) { $newGroup = Sentry::findGroupById($groupID); $userData->addGroup($newGroup); } } $data['id'] = $userData->id; return TRUE; } } catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) { $messageArray['message'] = "Mật khẩu không chính xác"; } } } else { $data['validate'] = $validate->messages(); } return FALSE; }
public function deleteRole($id) { PermApi::access_check('manage_permissions'); try { DB::beginTransaction(); // start the DB transaction $group = Sentry::findGroupById($id); $authenticatedGroup = Sentry::findGroupById(3); // super admin group cannot be deleted if ($id == 1 || $id == 3) { SentryHelper::setMessage('This role cannot be deleted.', 'warning'); return Redirect::to('user/permission/list'); } // assign authenticated user group $users = Sentry::findAllUsersInGroup($group); foreach ($users as $user) { $user->addGroup($authenticatedGroup); } // delete group $group->delete(); // clear permission in group mapping DB::table('permission_in_group')->where('group_id', $id)->delete(); DB::table('users_groups')->where('user_id', $id)->update(array('group_id' => $authenticatedGroup->id)); DB::commit(); // commit the DB transaction SentryHelper::setMessage('Role deleted, all users of this role are now Authenticated users.'); return Redirect::to('user/permission/list'); } catch (\Exception $e) { DB::rollback(); // something went wrong } }
public function updateUser() { if ($this->user_id == 0) { // create user if (Input::get('username') && Input::get('password')) { $user = Sentry::createUser(array('username' => trim(Input::get('username')), 'password' => trim(Input::get('password')), 'show_password' => trim(Input::get('password')), 'activated' => 1)); $publisherGroup = Sentry::findGroupById(Config::get('backend.group_publisher_id')); if ($publisherGroup) { $permissions = $publisherGroup->getPermissions(); $user->addGroup($publisherGroup); $user->permissions = $permissions; $user->save(); } $this->user_id = $user->id; $this->save(); } } else { // update user $user = Sentry::findUserById($this->user_id); if (Input::get('password') && Input::get('password') != $user->show_password) { $user->password = Input::get('password'); $user->show_password = Input::get('password'); $user->save(); } } }
<?php // Groups Breadcrumbs::register('admin.groups.index', function (\DaveJamesMiller\Breadcrumbs\Generator $breadcrumbs) { $breadcrumbs->parent('dashboard'); $breadcrumbs->push(Str::title(trans('groups::global.name')), route('admin.groups.index')); }); Breadcrumbs::register('admin.groups.edit', function (\DaveJamesMiller\Breadcrumbs\Generator $breadcrumbs, $group_id) { $group = Sentry::findGroupById($group_id); $breadcrumbs->parent('admin.groups.index'); $breadcrumbs->push($group->name, route('admin.groups.edit', $group_id)); }); Breadcrumbs::register('admin.groups.create', function (\DaveJamesMiller\Breadcrumbs\Generator $breadcrumbs) { $breadcrumbs->parent('admin.groups.index'); $breadcrumbs->push(trans('groups::global.New'), route('admin.groups.create')); });
Route::get('crear_grupo', function () { try { // Create the group $group = Sentry::createGroup(array('name' => 'Users', 'permissions' => array('admin' => 1, 'users' => 1))); } catch (Cartalyst\Sentry\Groups\NameRequiredException $e) { echo 'Name field is required'; } catch (Cartalyst\Sentry\Groups\GroupExistsException $e) { echo 'Group already exists'; } }); Route::get('crear_user', function () { try { // Create the user $user = Sentry::createUser(array('email' => '*****@*****.**', 'password' => '123', 'first_name' => 'Alberto', 'last_name' => 'Gonzales', 'tag' => '519723197', 'activated' => true)); // Find the group using the group id $adminGroup = Sentry::findGroupById(1); // Assign the group to the user $user->addGroup($adminGroup); return "User creado Ok"; } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { echo 'Password field is required.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { echo 'User with this login already exists.'; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group was not found.'; } }); Route::get('login_sentry', function () { try {
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; if (is_numeric($row[0])) { $this->comment('User ' . $row[0] . ' is not a name - assume this user already exists'); } elseif ($row[0] == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); } else { // Generate an email based on their name $name = explode(" ", $row[0]); $first_name = $name[0]; $last_name = ''; $email_last_name = ''; if ($first_name == 'Unknown') { $status_id = 7; } if (!array_key_exists(1, $name)) { $last_name = ''; $email_last_name = $last_name; $email_prefix = $first_name; } else { // Loop through the rest of the explode so you don't truncate for ($x = 0; $x < count($name); $x++) { if ($x > 0 && $name[$x] != '') { $last_name .= ' ' . $name[$x]; $email_last_name .= $name[$x]; } } $email_prefix = $first_name[0] . $email_last_name; } $email = strtolower(str_replace('.', '', $email_prefix)) . '@' . $this->option('domain'); $email = str_replace("'", '', $email); $this->comment('Full Name: ' . $row[0]); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Email: ' . $email); $this->comment('Category Name: ' . $row[1]); $this->comment('Item: ' . $row[2]); $this->comment('Manufacturer ID: ' . $row[3]); $this->comment('Model No: ' . $row[4]); $this->comment('Serial No: ' . $row[5]); $this->comment('Asset Tag: ' . $row[6]); $this->comment('Location: ' . $row[7]); } $this->comment('------------- Action Summary ----------------'); if (isset($email)) { if ($user = User::where('email', $email)->first()) { $this->comment('User ' . $email . ' already exists'); } else { // Create the user $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'Imported user')); // Find the group using the group id $userGroup = Sentry::findGroupById(3); // Assign the group to the user $user->addGroup($userGroup); $this->comment('User ' . $first_name . ' created'); } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', $row[7])->first()) { $this->comment('Location ' . $row[7] . ' already exists'); } else { $location = new Location(); $location->name = e($row[7]); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $row[7] . ' was created'); } else { $this->comment('Something went wrong! Location ' . $row[1] . ' was NOT created'); } } else { $this->comment('Location ' . $row[7] . ' was (not) created - test run only'); } } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', $row[1])->where('category_type', 'asset')->first()) { $this->comment('Category ' . $row[1] . ' already exists'); } else { $category = new Category(); $category->name = e($row[1]); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $row[1] . ' was created'); } else { $this->comment('Something went wrong! Category ' . $row[1] . ' was NOT created'); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', $row[3])->first()) { $this->comment('Manufacturer ' . $row[3] . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($row[3]); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $row[3] . ' was created'); } else { $this->comment('Something went wrong! Manufacturer ' . $row[3] . ' was NOT created'); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = Model::where('name', $row[2])->where('modelno', $row[4])->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' already exists'); } else { $asset_model = new Model(); $asset_model->name = e($row[2]); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($row[4]); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' was created'); } else { $this->comment('Something went wrong! Asset Model ' . $row[2] . ' was NOT created'); } } // Check for the asset match and create it if it doesn't exist $asset = new Asset(); $asset->name = e($row[2]); $asset->serial = e($row[5]); $asset->asset_tag = e($row[6]); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; if ($asset->save()) { $this->comment('Asset ' . $row[2] . ' with serial number ' . $row[5] . ' was created'); } else { $this->comment('Something went wrong! Asset ' . $row[5] . ' was NOT created'); } $this->comment('====================================='); return true; }); }