Esempio n. 1
0
 /**
  * Signup a new account with the given parameters
  *
  * @param  array $input Array containing 'username', 'email' and 'password'.
  *
  * @return  User User object that may or may not be saved successfully. Check the id to make sure.
  */
 public function signup($input)
 {
     $user = new User();
     $user->username = md5(uniqid(mt_rand(), true));
     $user->email = array_get($input, 'email');
     $user->password = array_get($input, 'password');
     $myRole = array_get($input, 'myrole');
     // The password confirmation will be removed from model
     // before saving. This field will be used in Ardent's
     // auto validation.
     $user->password_confirmation = array_get($input, 'password_confirmation');
     // Generate a random confirmation code
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // Save if valid. Password field will be hashed before save
     $user->save();
     if ($GLOBALS['APP-MAILING'] == false) {
         $user->confirmed = 1;
         $user->save();
     }
     // Add Role
     if ($user->id) {
         $role = Role::find($myRole);
         $user->roles()->attach($role);
     }
     return $user;
 }
Esempio n. 2
0
 public function initialize($user, $role)
 {
     $this->add(new Text("userName", array('placeholder' => '*Nombre de usuario', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Password("pass", array('placeholder' => '*Contraseña', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Password("pass2", array('placeholder' => '*Repita la contraseña', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Email("email", array('placeholder' => '*Email', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text("name_user", array('placeholder' => '*Nombre', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text("lastName", array('placeholder' => '*Apellido', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text("address_user", array('placeholder' => '*Dirección', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Select('state_user', array('' => '*Seleccionar Departamento', 'AMAZONAS' => 'AMAZONAS', 'ANTIOQUIA' => 'ANTIOQUIA', 'ARAUCA' => 'ARAUCA', 'ATLANTICO' => 'ATLANTICO', 'BOLIVAR' => 'BOLIVAR', 'BOYACA' => 'BOYACA', 'BOYACA' => 'BOYACA', 'CALDAS' => 'CALDAS', 'CAQUETA' => 'CAQUETA', 'CASANARE' => 'CASANARE', 'CAUCA' => 'CAUCA', 'CESAR' => 'CESAR', 'CHOCO' => 'CHOCO', 'CORDOBA' => 'CORDOBA', 'CUNDINAMARCA' => 'CUNDINAMARCA', 'GUAINIA' => 'GUAINIA', 'GUAJIRA' => 'GUAJIRA', 'GUAVIARE' => 'GUAVIARE', 'HUILA' => 'HUILA', 'MAGDALENA' => 'MAGDALENA', 'META' => 'META', 'NARIÑO' => 'NARIÑO', 'NTE_SANTANDER' => 'NORTE DE SANTANDER', 'PUTUMAYO' => 'PUTUMAYO', 'QUINDIO' => 'QUINDIO', 'RISARALDA' => 'RISARALDA', 'SAN_ANDRES' => 'SAN ANDRES Y PROVIDENCIA', 'SANTANDER' => 'SANTANDER', 'SUCRE' => 'SUCRE', 'TOLIMA' => 'TOLIMA', 'VALLE' => 'VALLE DEL CAUCA', 'VAUPES' => 'VAUPES', 'VICHADA' => 'VICHADA')));
     $this->add(new Select('city_user', array()));
     $this->add(new Text("phone_user", array('placeholder' => '*Teléfono', 'required' => 'required', 'class' => 'form-control')));
     $roles = Role::find();
     $r = array();
     if ($role->name == 'sudo') {
         foreach ($roles as $rol) {
             $r[$rol->idRole] = $rol->name;
         }
     } else {
         foreach ($roles as $rol) {
             if ($rol->name != 'sudo') {
                 $r[$rol->idRole] = $rol->name;
             }
         }
     }
     $this->add(new Select('idRole', $r, array('placeholder' => '*Funciones', 'required' => 'required', 'class' => 'form-control select2')));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $role = Role::find($id);
     $role->name = Input::get('name');
     $role->save();
     return Redirect::route('roles.index');
 }
Esempio n. 4
0
 public function getAcl()
 {
     //if (!isset($this->persistent->acl)) {
     $acl = new Phalcon\Acl\Adapter\Memory();
     $acl->setDefaultAction(Phalcon\Acl::DENY);
     //Register roles
     $rol = Role::find(array("cache" => array("key" => "role")));
     foreach ($rol as $ros) {
         $roles[strtolower($ros->name)] = new Phalcon\Acl\Role($ros->name);
     }
     foreach ($roles as $role) {
         $acl->addRole($role);
     }
     foreach (Action::find(array("cache" => array("key" => "action"))) as $actions) {
         $acl->addResource(new Phalcon\Acl\Resource($actions->controller->name), $actions->name);
     }
     //Grant access to public areas to both users and guests
     foreach ($rol as $role) {
         foreach ($role->action as $action) {
             $roledann[$role->name][$action->controller->name][] = $action->name;
         }
     }
     // print_r($roledann);
     foreach ($roledann as $keys => $dann) {
         foreach ($dann as $key => $dan) {
             $acl->allow($keys, $key, $dan);
         }
     }
     //The acl is stored in session, APC would be useful here too
     //$this->persistent->acl = $acl;
     //	}
     //return $this->persistent->acl;
     return $acl;
 }
 public function desasignar()
 {
     $rol = Role::find(Input::get('role_id'));
     $rolPermisos = RolesPermission::where('role_id', '=', Input::get('role_id'))->where('permission_id', '=', Input::get('permission_id'))->get()->first();
     $desasignar = RolesPermission::destroy($rolPermisos->id);
     return Response::json('ok');
 }
Esempio n. 6
0
 public function initialize($user, $thuser)
 {
     $roles = Role::find();
     $r = array();
     if ($thuser->idRole == 1) {
         foreach ($roles as $rol) {
             $r[$rol->idRole] = $rol->name;
         }
     } else {
         foreach ($roles as $rol) {
             if ($rol->name != 'sudo') {
                 $r[$rol->idRole] = $rol->name;
             }
         }
     }
     $this->add(new Select('idRole', $r, array('required' => 'required', 'class' => 'select2 select')));
     $this->add(new Check('status', array('type' => 'checkbox', 'class' => 'bootstrap-switch')));
     $this->add(new Text('email', array('maxlength' => 100, 'type' => 'email', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text('userName', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Password('password1', array('maxlength' => 50, 'type' => 'text', 'required' => 'password', 'class' => 'form-control')));
     $this->add(new Password('password2', array('maxlength' => 50, 'type' => 'password', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text('name', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text('lastName', array('maxlength' => 40, 'type' => 'text', 'required' => 'required', 'class' => 'form-control')));
     $this->add(new Text('phone', array('maxlength' => 50, 'type' => 'text', 'class' => 'form-control')));
 }
 /**
  * Store a newly created resource in storage.
  * POST /users
  *
  * @return Response
  */
 public function store()
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $validation = Validator::make($input, User::$rules);
     if ($validation->passes()) {
         DB::transaction(function () {
             $user = new User();
             $user->first_name = strtoupper(Input::get('first_name'));
             $user->middle_initial = strtoupper(Input::get('middle_initial'));
             $user->last_name = strtoupper(Input::get('last_name'));
             $user->dept_id = Input::get('department');
             $user->confirmed = 1;
             $user->active = 1;
             $user->email = Input::get('email');
             $user->username = Input::get('username');
             $user->password = Input::get('password');
             $user->password_confirmation = Input::get('password_confirmation');
             $user->confirmation_code = md5(uniqid(mt_rand(), true));
             $user->image = "default.png";
             $user->save();
             $role = Role::find(Input::get('name'));
             $user->roles()->attach($role->id);
         });
         return Redirect::route('user.index')->with('class', 'success')->with('message', 'Record successfully added.');
     } else {
         return Redirect::route('user.create')->withInput(Input::except(array('password', 'password_confirmation')))->withErrors($validation)->with('class', 'error')->with('message', 'There were validation errors.');
     }
 }
 public static function destroy($id)
 {
     $role = Role::find($id);
     $role->destroy();
     flash('Role removed successfully!');
     Redirect::to('/roles');
 }
 public function run()
 {
     $faker = Faker::create();
     Permission::truncate();
     DB::table('permission_role')->truncate();
     Permission::create(['action' => 'User.create']);
     Permission::create(['action' => 'User.view']);
     Permission::create(['action' => 'User.update']);
     Permission::create(['action' => 'User.delete']);
     Permission::create(['action' => 'Category.create']);
     Permission::create(['action' => 'Category.view']);
     Permission::create(['action' => 'Category.update']);
     Permission::create(['action' => 'Category.delete']);
     Permission::create(['action' => 'Post.create']);
     Permission::create(['action' => 'Post.view']);
     Permission::create(['action' => 'Post.update']);
     Permission::create(['action' => 'Post.delete']);
     Permission::create(['action' => 'Comment.create']);
     Permission::create(['action' => 'Comment.view']);
     Permission::create(['action' => 'Comment.update']);
     Permission::create(['action' => 'Comment.delete']);
     Permission::create(['action' => 'Role.create']);
     Permission::create(['action' => 'Role.view']);
     Permission::create(['action' => 'Role.update']);
     Permission::create(['action' => 'Role.delete']);
     Permission::create(['action' => 'Permission.create']);
     Permission::create(['action' => 'Permission.view']);
     Permission::create(['action' => 'Permission.update']);
     Permission::create(['action' => 'Permission.delete']);
     $admin = Role::find(1);
     $admin->permissions()->sync(range(1, 24));
 }
Esempio n. 10
0
 public function storeUser()
 {
     $validator = Validator::make($data = Input::all(), User::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $user = new User();
     $user->username = $data['username'];
     $user->email = $data['email'];
     $user->password = $data['password'];
     $user->password_confirmation = $data['password_confirmation'];
     if (isset($data['tipe'])) {
         $user->tipe = $data['tipe'];
         $user->nama = $data['nama'];
         $user->alamat = $data['alamat'];
         $user->telp = $data['telp'];
     }
     $user->confirmed = 1;
     $user->save();
     if ($data['role'] == '0') {
         $user->attachRole(Role::find(6));
     } elseif ($data['role'] == '1') {
         $user->attachRole(Role::find(3));
     } elseif ($data['role'] == '2') {
         $user->attachRole(Role::find(4));
         $outlet = new Outlet();
         $outlet->user_id = $user->id;
         $name = 'Outlet ' . $user->username . '';
         $outlet->name = $name;
         $outlet->save();
     }
     return Redirect::to('admin/users')->with('message', 'berhasil menambahkan user');
 }
Esempio n. 11
0
 public function initialize($entity = null, $options = null)
 {
     $role = new Select('roleid', Role::find(), array('using' => array('id', 'role'), 'useEmpty' => TRUE, 'emptyText' => $this->di->get('translate')->_('Seleccione un Rol')));
     $role->setLabel('Rol');
     $this->add($role);
     //añadimos un botón de tipo submit
     $submit = $this->add(new Submit('Guardar', array('class' => 'btn btn-success')));
 }
Esempio n. 12
0
 public function getRoleAttribute()
 {
     if ($this->role_id == '0') {
         return 'Няма';
     } else {
         return Role::find($this->role_id)->name;
     }
 }
Esempio n. 13
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function find($id)
 {
     $model = Role::find($id);
     if ($model) {
         return $model;
     }
     return 'Role not found.';
 }
 public function delete()
 {
     //check if the role already exist...
     $id = Input::get('id');
     $role = Role::find($id);
     $role->delete();
     return Response::jsend('success', array('msg' => 'Role successfully deleted.'));
 }
 public function delete($id)
 {
     $role = Role::find($id);
     $role->delete();
     // redirect
     Session::flash('message', 'Successfully deleted the role!');
     return Redirect::to('admin/role');
 }
Esempio n. 16
0
 /**
  * Delete role
  * 
  * @return Response
  */
 public function destroy($id)
 {
     $role = Role::find($id);
     if ($role->delete()) {
         return $this->respondNoContent();
     }
     return $this->respondServerError();
 }
Esempio n. 17
0
 public function run()
 {
     $admin = Role::find(1);
     $read = Permission::find(1);
     $admin->attachPermission($read);
     $user1 = User::find(1);
     $user1->attachRole($admin);
 }
 public function run()
 {
     $permissions = array('Manage Users', 'Manage Roles', 'Manage Permissions', 'Manage Openings', 'Manage Settings');
     foreach ($permissions as $permission) {
         Permission::create(['name' => $permission, 'slug' => $permission, 'description' => $permission]);
     }
     $permissions = Permission::lists('id');
     Role::find(1)->permissions()->attach($permissions);
 }
Esempio n. 19
0
 public function frmAction($id = NULL)
 {
     $user = $this->getInstance($id);
     $roles = Role::find();
     $this->view->setVars(array("user" => $user, "siteUrl" => $this->url->getBaseUri(), "baseHref" => $this->dispatcher->getControllerName(), "roles" => $roles));
     $this->view->pick("users/edit");
     $_SESSION['bread']['object'] = $user;
     parent::frmAction($id);
 }
 public function testDelete()
 {
     // Set SOURCE URL - the index page for roles
     Session::put('SOURCE_URL', URL::route('role.index'));
     $this->action('GET', 'RoleController@delete', array("id" => 2));
     $role2 = Role::find(2);
     $this->assertNull($role2);
     $this->assertRedirectedToRoute('role.index');
 }
 /**
  * Make changes to the database.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('users', function ($table) {
         $table->increments('id');
         $table->string('email')->unique();
         $table->string('password');
         $table->string('name');
         $table->integer('age');
         $table->timestamps();
     });
     User::create(array('id' => 1, 'email' => '*****@*****.**', 'password' => Hash::make('test'), 'name' => 'I am Administrator', 'age' => 40));
     User::create(array('id' => 2, 'email' => '*****@*****.**', 'password' => Hash::make('test'), 'name' => 'I am Staff', 'age' => 30));
     User::create(array('id' => 3, 'email' => '*****@*****.**', 'password' => Hash::make('test'), 'name' => 'I am Member', 'age' => 25));
     User::create(array('id' => 4, 'email' => '*****@*****.**', 'password' => Hash::make('test'), 'name' => 'I am Member and Staff', 'age' => 17));
     Schema::create('roles', function ($table) {
         $table->increments('id');
         $table->string('name');
         $table->timestamps();
     });
     Role::create(array('id' => 1, 'name' => 'Admin'));
     Role::create(array('id' => 2, 'name' => 'Staff'));
     Role::create(array('id' => 3, 'name' => 'Member'));
     Schema::create('rules', function ($table) {
         $table->increments('id');
         $table->string('group');
         $table->string('action');
         $table->string('description');
         $table->timestamps();
     });
     Rule::create(array('id' => 1, 'group' => 'demo', 'action' => '*', 'description' => 'Can access Demo all actions.'));
     Rule::create(array('id' => 2, 'group' => 'demo', 'action' => 'view', 'description' => 'Can view Demo.'));
     Rule::create(array('id' => 3, 'group' => 'demo', 'action' => 'create', 'description' => 'Can create Demo.'));
     Rule::create(array('id' => 4, 'group' => 'demo', 'action' => 'edit', 'description' => 'Can edit Demo.'));
     Rule::create(array('id' => 5, 'group' => 'demo', 'action' => 'revise', 'description' => 'Can revise Demo.'));
     Rule::create(array('id' => 6, 'group' => 'demo', 'action' => 'publish', 'description' => 'Can publish Demo.'));
     Rule::create(array('id' => 7, 'group' => 'demo', 'action' => 'delete', 'description' => 'Can delete Demo.'));
     Schema::create('role_rule', function ($table) {
         $table->increments('id');
         $table->integer('role_id');
         $table->integer('rule_id');
         $table->timestamps();
     });
     Role::find(1)->rules()->sync(array(1));
     Role::find(2)->rules()->sync(array(2, 5, 6, 7));
     Role::find(3)->rules()->sync(array(2, 4, 3));
     Schema::create('role_user', function ($table) {
         $table->increments('id');
         $table->integer('user_id');
         $table->integer('role_id');
         $table->timestamps();
     });
     User::find(1)->roles()->attach(1);
     User::find(2)->roles()->attach(2);
     User::find(3)->roles()->attach(3);
     User::find(4)->roles()->sync(array(2, 3));
 }
 public function __construct($configs)
 {
     parent::__construct($configs);
     $this->load('Services\\Auth', $configs->auth->after_login, $configs->auth->after_logout, true);
     $this->auth->redirectCheck();
     $user_id = $this->auth->getUserId();
     $user = User::find($user_id);
     $role = Role::find($user->role_id);
     $this->load('Helpers\\Menu', $this->request, $this->configs, $role->role);
     $this->view->setTitle('HXPHP - Administrativo')->setVar('user', $user);
 }
Esempio n. 23
0
 static function getLookup()
 {
     $role = new Role();
     $role->orderBy('name');
     $role->find();
     $roleList = array();
     while ($role->fetch()) {
         $roleList[$role->roleId] = $role->name . ' - ' . $role->description;
     }
     return $roleList;
 }
Esempio n. 24
0
 public function getRolesPermissions($roles)
 {
     $temp = [];
     if (is_array($roles)) {
         foreach ($roles as $role => $id) {
             $temp += unserialize(Role::find($id)->permissions);
         }
         return $temp;
     }
     return [];
 }
Esempio n. 25
0
 public function signinAction($isAjax = false)
 {
     $roles = Role::find();
     $this->jquery->postFormOnClick(".validate", "Auth/login", "frmLogin", "#content");
     $this->jquery->getOnClick(".fastConnect", "Auth/fastConnect", "#content");
     $this->jquery->compile($this->view);
     if ($isAjax) {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     }
     $this->view->setVar("roles", $roles);
     $this->view->pick("Auth/signin");
 }
Esempio n. 26
0
 public function delete(array $input)
 {
     if (isset($input['id'])) {
         $id = $input['id'];
         /* @var $role Role */
         $role = Role::find($id);
         $role->delete();
         return [true];
     } else {
         return [false];
     }
 }
Esempio n. 27
0
 public function UpdateListRole()
 {
     $input = Input::all();
     $listRoleID = $input['update_list_role_id'];
     $listRoleID = explode(",", $listRoleID);
     foreach ($listRoleID as $p) {
         if ($input['name'] != '') {
             $role = Role::find($p);
             $role->name = $input['name'];
             $role->save();
         }
     }
 }
Esempio n. 28
0
 /**
  * makeSupperUser 
  *
  * 创建超极管理员
  * 
  * @param mixed $uname 
  * @param mixed $pwd 
  * @return bool
  */
 public static function initSupperUser($uname, $pwd)
 {
     $user = new User();
     $userInfo = $user->getUserWithRole('uname=:name', array(':name' => $uname));
     if (empty($userInfo)) {
         // make user
         $user->uname = $uname;
         $user->email = '';
         $user->pwd = $pwd;
         $user->rid = 0;
         $user->save();
     }
     // make role
     $role = new Role();
     $rname = 'superman';
     $roleInfo = $role->find('rname=:name', array(':name' => $rname));
     if (empty($roleInfo)) {
         $params = array('name' => $rname, 'actions' => array());
         $action = new Action();
         $actionList = $action->findAll();
         foreach ($actionList as $k => $v) {
             $params['actions'][] = $v['aid'];
         }
         $role->saveRole($params);
         // save rid
         $userInfo = $user->getUserWithRole('uname=:name', array(':name' => $uname));
         $roleInfo = $role->find('rname=:name', array(':name' => $rname));
         $user->updateByPk($userInfo[0]['uid'], array('uname' => $uname, 'email' => '', 'pwd' => $pwd, 'rid' => $roleInfo['rid']));
     } else {
         $params = array('id' => $roleInfo['rid'], 'name' => $rname, 'actions' => array());
         $action = new Action();
         $actionList = $action->findAll();
         foreach ($actionList as $k => $v) {
             $params['actions'][] = $v['aid'];
         }
         $role->updateRole($params);
     }
     return true;
 }
Esempio n. 29
0
 public static function can($action, $entity)
 {
     $roleid = Auth::user()->roleId;
     $role = Role::find($roleid);
     if ($role) {
         if ($role->{$entity . '_' . $action} == 'on') {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
 /**
 * Store a newly created resource in storage.
 * POST /administratorclub
 *
 * @return Response
 */
 public function store()
 {
     $uuid = Uuid::generate();
     $validator = Validator::make(Input::all(), AdministratorClub::$rules);
     if ($validator->passes()) {
         $repo = App::make('UserRepository');
         $user = $repo->signup(Input::all());
         $role = Role::find(2);
         $user->attachRole($role);
         if ($user->id) {
             $profile = new Profile();
             $profile->user_id = $user->id;
             $profile->firstname = Input::get('firstname');
             $profile->lastname = Input::get('lastname');
             $profile->mobile = Input::get('mobile');
             $profile->avatar = '/img/coach-avatar.jpg';
             $profile->save();
             $club = new Club();
             $club->id = $uuid;
             $club->name = Input::get('name');
             $club->sport = 'lacrosse';
             $club->phone = Input::get('contactphone');
             $club->website = Input::get('website');
             $club->email = Input::get('contactemail');
             $club->add1 = Input::get('add1');
             $club->city = Input::get('city');
             $club->state = Input::get('state');
             $club->zip = Input::get('zip');
             $club->logo = Input::get('logo');
             $club->waiver = Input::get('waiver');
             $club->processor_user = Crypt::encrypt(Input::get('processor_user'));
             $club->processor_pass = Crypt::encrypt(Input::get('processor_pass'));
             $club->save();
             $clubs = Club::find($uuid);
             $clubs->users()->save($user);
             if (Config::get('confide::signup_email')) {
                 Mail::queueOn(Config::get('confide::email_queue'), Config::get('confide::email_account_confirmation'), compact('user'), function ($message) use($user) {
                     $message->to($user->email, $user->username)->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
                 });
             }
             return Redirect::action('UsersController@login')->with('notice', Lang::get('confide::confide.alerts.account_created'));
         } else {
             $error = $user->errors()->all(':message');
             return Redirect::back()->withInput(Input::except('password'))->withErrors($error);
         }
     }
     return Redirect::back()->withErrors($validator)->withInput();
 }