public function post_create()
 {
     $rules = array('username' => 'required|unique:users|max:255', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'email' => 'required|email', 'password' => 'confirmed');
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         Messages::add('error', $validation->errors->all());
         return Redirect::to('admin/' . $this->views . '/create')->with_input();
     } else {
         $usr = new User();
         $usr->username = Input::get('username');
         $usr->email = Input::get('email');
         $usr->first_name = Input::get('first_name');
         $usr->last_name = Input::get('last_name');
         $usr->active = 1;
         $usr->admin = Input::get('admin') ? 1 : 0;
         if (Input::get('password')) {
             $usr->password = Input::get('password');
         }
         $usr->save();
         $usr->roles()->delete();
         if (Input::get('roles')) {
             foreach (Input::get('roles') as $rolekey => $val) {
                 $usr->roles()->attach($rolekey);
             }
         }
         Messages::add('success', 'New User Added');
         return Redirect::to('admin/' . $this->views . '');
     }
 }
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     // DB::table('departments')->truncate();
     //    $department = new Department;
     //    $department->department_desc = 'ADMIN';
     //    $department->save();
     DB::table('roles')->truncate();
     $role = new Role();
     $role->name = 'ADMINISTRATOR';
     $role->save();
     DB::table('users')->truncate();
     DB::table('assigned_roles')->truncate();
     $user = new User();
     $user->username = '******';
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->password_confirmation = '031988';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // $user->confirmed = 1;
     // $user->active = 1;
     // $user->department_id = $department->id;
     $user->save();
     $user->roles()->attach($role->id);
     // id only
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Example #3
0
 /**
  * Stores new account
  *
  */
 public function store()
 {
     $user = new User();
     $user->first_name = Input::get('first_name');
     $user->last_name = Input::get('last_name');
     $user->username = Input::get('username');
     $user->email = Input::get('email');
     $user->password = Input::get('password');
     User::setRules('store');
     // Hacky workaround for: https://github.com/laravelbook/ardent/issues/152
     if (app()->env === 'testing') {
         unset(User::$rules['password_confirmation']);
         unset(User::$rules['password']);
     } else {
         $user->password_confirmation = Input::get('password_confirmation');
     }
     $user->save();
     if ($user->getKey()) {
         $notice = Lang::get('confide::confide.alerts.account_created') . ' ' . Lang::get('confide::confide.alerts.instructions_sent');
         $user->roles()->sync([6]);
         // Redirect with success message, You may replace "Lang::get(..." for your custom message.
         return Redirect::action('AuthController@login')->with('notice', $notice);
     } else {
         // Get validation errors (see Ardent package)
         $error = $user->errors()->all(':message');
         return Redirect::action('AuthController@create')->withInput(Input::except('password'))->with('error', $error);
     }
 }
Example #4
0
 public static function has($role, $roles = 0)
 {
     if ($roles === 0) {
         $roles = User::roles();
     }
     return in_array($role, $roles);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required | email', 'password' => 'required', 'password_confirmation' => 'required | same:password');
     $validator = Validator::make(Input::all(), $rules);
     $input = Input::all();
     if ($validator->fails()) {
         $input['autoOpenModal'] = true;
         //var_dump($input);die;
         return Redirect::back()->withErrors($validator)->withInput($input);
     } else {
         $user = new User();
         $user->first_name = Input::get('first_name');
         $user->last_name = Input::get('last_name');
         $user->password = Hash::make(Input::get('password'));
         $user->status = 3;
         $user->save();
         $userEmail = new UserEmail();
         $userEmail->address = Input::get('email');
         $userEmail->token = $userEmail->createToken();
         $userEmail->confirmed = true;
         $user->email()->save($userEmail);
         $user->roles()->attach(3);
         $users = User::with(['roles', 'email'])->get();
         //Session::flash('message', 'Successfully created nerd!');
         return Redirect::to('admin/user')->with('users', $users);
     }
     //return "hello";
 }
Example #6
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;
 }
 /**
  * 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.');
     }
 }
Example #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Crear Usuario
     $data = Input::all();
     $rules = array('username' => 'required|numeric|min:7|unique:users', 'password' => 'required|confirmed', 'email' => 'required|email|unique:users', 'nombre' => 'required|alpha_spaces', 'cargo' => 'alpha_spaces', 'prefijo' => 'alpha|max:5', 'iniciales' => 'alpha|max:5');
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $user = new User();
         $user->username = Input::get('username');
         $user->email = Input::get('email');
         $user->password = Hash::make(Input::get('password'));
         $user->nombre = Input::get('nombre');
         $user->cargo = Input::get('cargo');
         $user->prefijo = Input::get('prefijo');
         $user->iniciales = Input::get('iniciales');
         $user->save();
         //Asociar con Roles
         $role_user = Input::get('role_user');
         foreach ($role_user as $role) {
             $user->roles()->attach($role);
         }
         return Redirect::action('UsuarioController@show', array($user->id));
     } else {
         return Redirect::action('UsuarioController@create')->withErrors($validator)->withInput();
     }
 }
Example #9
0
 public function init()
 {
     self::$roles = array(self::ROLE_ADMIN => tt('RoleAdmin', 'users'), self::ROLE_MODERATOR => tt('RoleModerator', 'users'), self::ROLE_REGISTERED => tt('RoleRegistered', 'users'));
     self::$createUserWithoutRolesAdmin = self::$createUserWithoutRolesModeration = self::$roles;
     unset(self::$createUserWithoutRolesAdmin['admin']);
     unset(self::$createUserWithoutRolesModeration['admin'], self::$createUserWithoutRolesModeration['moderator']);
     parent::init();
 }
Example #10
0
 public function run()
 {
     Eloquent::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     // Roles
     DB::table('roles')->delete();
     Role::create(array('name' => 'Admin'));
     Role::create(array('name' => 'Manager'));
     Role::create(array('name' => 'Player'));
     // Users
     DB::table('users')->delete();
     // Admin
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->username = '******';
     $user->password_confirmation = 'Birdie002$';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user ' . $user->email);
     }
     $userRole = DB::table('roles')->where('name', '=', 'Admin')->pluck('id');
     $user->roles()->attach($userRole);
     // Manager
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->username = '******';
     $user->password_confirmation = '1111';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user ' . $user->email);
     }
     $userRole = DB::table('roles')->where('name', '=', 'Manager')->pluck('id');
     $user->roles()->attach($userRole);
     // Player
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->username = '******';
     $user->password_confirmation = '1111';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user ' . $user->email);
     }
     $userRole = DB::table('roles')->where('name', '=', 'Player')->pluck('id');
     $user->roles()->attach($userRole);
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Example #11
0
 public function postAdd()
 {
     $rules = ['firstname' => 'required|min:2', 'lastname' => 'required|min:2', 'address' => 'required|min:5', 'phone' => 'required|min:7'];
     if (!Auth::check()) {
         array_push($rules, ['email' => 'required|email|unique:users']);
     }
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to("checkout")->withErrors($validator)->withInput(Input::except(''));
     } else {
         if (Auth::check()) {
             $user = User::find(Auth::user()->id);
         } else {
             $user = new User();
             $user->email = Input::get('email');
             $password = str_random(10);
             $user->password = Hash::make($password);
         }
         $user->firstname = Input::get('firstname');
         $user->lastname = Input::get('lastname');
         $user->address = Input::get('address');
         $user->phone = Input::get('phone');
         if ($user->save()) {
             $role = Role::where('name', '=', 'Customer')->first();
             if (!$user->hasRole("Customer")) {
                 $user->roles()->attach($role->id);
             }
             $order = new Order();
             $order->user_id = $user->id;
             $order->status_id = OrderStatus::where('title', '=', 'Новый')->first()->id;
             $order->comment = 'Телефон: <b>' . $user->phone . '</b><br>Адрес: <b>' . $user->address . '</b><br>Комментарий покупателя: ' . '<i>' . Input::get('comment') . '</i>';
             if ($order->save()) {
                 $cart = Cart::content();
                 foreach ($cart as $product) {
                     $orderDetails = new OrderDetails();
                     $orderDetails->order_id = $order->id;
                     $orderDetails->product_id = $product->id;
                     $orderDetails->quantity = $product->qty;
                     $orderDetails->price = $product->price;
                     $orderDetails->save();
                 }
             }
             if (!Auth::check()) {
                 Mail::send('mail.registration', ['firstname' => $user->firstname, 'login' => $user->email, 'password' => $password, 'setting' => Config::get('setting')], function ($message) {
                     $message->to(Input::get('email'))->subject("Регистрация прошла успешно");
                 });
             }
             $orderId = $order->id;
             Mail::send('mail.order', ['cart' => $cart, 'order' => $order, 'phone' => $user->phone, 'user' => $user->firstname . ' ' . $user->lastname], function ($message) use($orderId) {
                 $message->to(Input::get('email'))->subject("Ваша заявка №{$orderId} принята");
             });
             Cart::destroy();
             return Redirect::to("checkout/thanks/spasibo-vash-zakaz-prinyat")->with('successcart', 'ok', ['cart' => $cart]);
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $user = new User();
     if (Input::get('lastname')) {
         $user->lastname = Input::get('lastname');
     }
     if (Input::get('firstname')) {
         $user->firstname = Input::get('firstname');
     }
     if (Input::get('username')) {
         $user->username = Input::get('username');
     }
     if (Input::get('email')) {
         $user->email = Input::get('email');
     }
     if (Input::get('password')) {
         $user->password = Hash::make(Input::get('password'));
     }
     if (Input::get('position')) {
         $user->position = Input::get('position');
     }
     if (Input::get('identification')) {
         $user->identification = Input::get('identification');
     }
     if (Input::get('telephone')) {
         $user->telephone = Input::get('telephone');
     }
     if (Input::get('cellphone')) {
         $user->cellphone = Input::get('cellphone');
     }
     if (Input::get('enable')) {
         $user->enable = Input::get('enable');
     }
     $user->save();
     if (Input::get('profile')) {
         $profile = Input::get('profile');
         $user->profile = Input::get('profile');
         $user->roles()->sync(User::makeProfile($profile));
         $user->save();
     }
     //Imagen asociada
     if (Input::hasFile('file')) {
         $f = Input::file('file');
         if ($f) {
             $att = new Attachment();
             $att->user_id = $user->id;
             $r = array();
             $r = AttachmentController::uploadAttachment($f, $att);
         }
     }
     return Redirect::to('admin/user');
 }
Example #13
0
 public function createUsersPlayersTest($nbPlayer = 2)
 {
     // Set Php Time Out
     ini_set('max_execution_time', 300);
     //300 seconds = 5 minutes
     // Suppression des Users & Players de Test
     $deletedUsers = User::where('email', 'LIKE', '%aa.be')->delete();
     // Boucle
     $createdUsers = 0;
     $messageRetour = '';
     for ($u = 1; $u <= $nbPlayer; $u++) {
         // 1-Auto Values
         $autoNom = 'Player-' . $u;
         $autoPrenom = 'player ' . $u;
         $autoMail = 'player_' . $u . '@aa.be';
         // 2-Create User with role = Player (3)
         $user = new User();
         $user->email = $autoMail;
         $user->password = '******';
         $user->username = $autoNom;
         $user->password_confirmation = '1111';
         $user->confirmation_code = md5(uniqid(mt_rand(), true));
         $user->confirmed = 1;
         if (!$user->save()) {
             $messageRetour .= 'Unable to create user ' . $user->email;
             $messageRetour .= print_r($user->errors());
             $messageRetour .= '<hr>';
         } else {
             $messageRetour .= $u . ' Created user ' . $user->email;
             $messageRetour .= '<hr>';
             $userRole = DB::table('roles')->where('name', '=', 'Player')->pluck('id');
             $user->roles()->attach($userRole);
             // 3-Create Player
             $userId = $user->id;
             $autoNation = rand(2, 4);
             $autoHcp = rand(0, 360) / 10;
             $autoLangue = rand(1, 3);
             $autoClub = rand(2, 7);
             $autosexe = rand(1, 2);
             $autoLicence = 'TEST' . $u;
             $year = rand(1950, 2006);
             $month = rand(1, 12);
             $day = rand(1, 28);
             Player::create(array('user_id' => $userId, 'nom' => $autoNom, 'prenom' => $autoPrenom, 'nation_id' => $autoNation, 'hcp' => $autoHcp, 'langue_id' => $autoLangue, 'club_id' => $autoClub, 'statusplayer_id' => 1, 'sexe_id' => $autosexe, 'naissance' => Carbon::createFromDate($year, $month, $day), 'licence' => $autoLicence));
             $createdUsers++;
         }
     }
     return $messageRetour;
 }
 /**
  * Post register page
  */
 public function postRegister()
 {
     $rules = ['username' => 'required|unique:users,username|min:5|max:20', 'password' => 'required|min:5|max:20', 'email' => 'required|email|unique:users', 'nickname' => 'required|unique:users,nickname|min:2|max:10'];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         $user = new User();
         $user->username = Input::get('username');
         $user->email = Input::get('email');
         $user->password = Hash::make(Input::get('password'));
         $user->nickname = Input::get('nickname');
         $user->save();
         $user->roles()->attach(3, ['created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
         return Redirect::to('')->with('success', '회원가입이 되었습니다.');
     }
     return Redirect::to('register')->withInput(Input::all())->withErrors($validator);
 }
Example #15
0
 /**
  * Displays a list of all users
  *
  * @uses  Request::is_datatables
  * @uses  ORM::dataTables
  * @uses  Text::plain
  * @uses  Text::auto_link
  * @uses  User::roles
  * @uses  HTML::anchor
  * @uses  HTML::icon
  * @uses  Route::get
  * @uses  Route::url
  * @uses  Date::formatted_time
  * @uses  Assets::popup
  */
 public function action_list()
 {
     $is_datatables = Request::is_datatables();
     if ($is_datatables) {
         $users = ORM::factory('user');
         // @todo fix dummy id column for roles to match the column order
         $this->_datatables = $users->dataTables(array('name', 'mail', 'created', 'login', 'id', 'status'));
         foreach ($this->_datatables->result() as $user) {
             $this->_datatables->add_row(array(HTML::anchor($user->url, Text::plain($user->nick)), Text::auto_link($user->mail), Date::formatted_time($user->created, 'M d, Y'), $user->login > 0 ? Date::formatted_time($user->login, 'M d, Y') : __('Never'), User::roles($user), $user->status == 1 ? '<span class="status-active"><i class="fa fa-check-circle"></i></span>' : '<span class="status-blocked"><i class="fa fa-ban"></i></span>', HTML::icon(Route::get('admin/user')->uri(array('action' => 'edit', 'id' => $user->id)), 'fa-edit', array('class' => 'action-edit', 'title' => __('Edit User'))) . '&nbsp;' . HTML::icon(Route::get('admin/permission')->uri(array('action' => 'user', 'id' => $user->id)), 'fa-key', array('class' => '', 'title' => __('Edit Permission'))) . '&nbsp;' . HTML::icon($user->delete_url, 'fa-trash-o', array('class' => 'action-delete', 'title' => __('Delete User'), 'data-toggle' => 'popup', 'data-table' => '#admin-list-users'))));
         }
     }
     Assets::popup();
     $this->title = __('Users');
     $url = Route::url('admin/user', array('action' => 'list'), TRUE);
     $view = View::factory('admin/user/list')->bind('datatables', $this->_datatables)->set('is_datatables', $is_datatables)->set('url', $url);
     $this->response->body($view);
 }
 public function postRegister()
 {
     $data = Input::all();
     $rules = array('username' => 'required|min:3|max:32', 'email' => 'required|email', 'password' => 'required|confirmed|min:8');
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $user = new User();
         $user->username = Input::get('username');
         $user->email = Input::get('email');
         $user->password = Hash::make(Input::get('password'));
         $user->save();
         $role = Role::where('name', 'User')->first();
         $user->roles()->attach($role);
         Auth::login($user);
         return Redirect::to('/');
     }
     return Redirect::route('register')->withErrors($validator)->withInput();
 }
Example #17
0
 public function run()
 {
     $roles = Role::all();
     // Create users
     $users = ['admin' => ['email' => '*****@*****.**', 'roles' => $roles->toArray()], 'jason' => ['email' => '*****@*****.**', 'roles' => []], 'test1' => ['email' => '*****@*****.**', 'roles' => []], 'test2' => ['email' => '*****@*****.**', 'roles' => []]];
     foreach ($users as $username => $data) {
         $user = new User();
         $user->username = $username;
         $user->email = $data['email'];
         $user->password = $user->password_confirmation = 'password';
         $user->created_at = $user->updated_at = new DateTime();
         $user->confirmed = 1;
         $user->status = 1;
         $user->save();
         if ($data['roles']) {
             $r_ids = [];
             foreach ($data['roles'] as $role) {
                 $r_ids[] = $role['id'];
             }
             $user->roles()->sync($r_ids);
         }
     }
 }
 public function store()
 {
     $rules = array('username' => 'required|unique:users,username', 'password' => 'required|min:6', 'email' => 'required|email|unique:users,email', 'name' => 'required', 'age' => 'required|numeric', 'roles' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('admin/user/create')->withErrors($validator)->withInput();
     } else {
         // store
         $user = new User();
         $user->name = Input::get('name');
         $user->password = Hash::make(Input::get('password'));
         $user->username = Input::get('username');
         $user->email = Input::get('email');
         $user->age = Input::get('age');
         $user->save();
         foreach (Input::get('roles') as $roleId) {
             $user->roles()->attach($roleId);
         }
         // redirect
         Session::flash('message', 'Successfully created user!');
         return Redirect::to('admin/user');
     }
 }
Example #19
0
 /**
  * Store a newly created resource in storage.
  * POST /users
  *
  * @return Response
  */
 public function store()
 {
     $validator = User::validate(Input::all());
     $token = Input::get('token');
     if ($validator->fails()) {
         return $this->respondInsufficientPrivileges($validator->messages()->all());
     }
     $smsEntry = SMS::where('token', $token)->orderBy('id')->first();
     if (!$smsEntry) {
         return $this->respondInsufficientPrivileges('user.invalid-token');
     }
     if (!$smsEntry->verified) {
         return Response::json(['error' => ['message' => 'Your number is not yet verified. Please re-register.', 'status' => 1]], 403);
     }
     $device = Device::create(['udid' => $smsEntry->device, 'auth_token' => base64_encode(openssl_random_pseudo_bytes(32)), 'phone' => $smsEntry->phone]);
     $phone = Phone::create(['number' => $smsEntry->phone]);
     $user = new User(Input::all());
     if (Input::hasFile('img')) {
         $user->setAvatar(Input::file('img'));
     } else {
         //FIXME cant get default postgres value to work
         //			$user->img_origin = S3_PUBLIC.'placeholder_128.png';
         //			$user->img_middle = S3_PUBLIC.'placeholder_128.png';
         //			$user->img_small = S3_PUBLIC.'placeholder_64.png';
     }
     $user->phone_id = $phone->id;
     $user->password = Input::get('password');
     $user->urgent_calls = 2;
     $user->save();
     $user->roles()->attach(3);
     // user role
     $user->devices()->save($device);
     $user->phones()->save($phone);
     $user->subscriptions()->attach([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 56, 57, 58]);
     //		Category::updateSubsCounts();
     $smsEntry->delete();
     $response['user'] = $this->collectionTransformer->transformUserToSmall($user);
     $response['auth_token'] = $device->auth_token;
     return $this->respond($response);
     //		Mail::send('emails.verify', ['token' => $user->verification_code], function($message) use ($user) {
     //			$message->to($user->email, $user->name.' '.$user->family_name)->subject('Verify your account');
     //		});
 }
Example #20
0
}
?>
            <dt><?php 
echo t('status');
?>
</dt>
            <dd><?php 
echo t($this->user->is_active ? 'active' : 'inactive');
?>
</dd>
            <dt><?php 
echo t('role');
?>
</dt>
            <dd><?php 
echo h(User::roles($this->user->role));
?>
</dd>
            <dt><?php 
echo t('description');
?>
</dt>
            <dd>
                <?php 
print wysiwyg($this->user->description);
?>
            </dd>
        </dl>
    </article>

    <?php 
Example #21
0
 /**
  * Setup database connection for tests
  */
 public function setUp()
 {
     /*
      * Setup connection with sqlite
      */
     $capsule = new Capsule();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     /*
      * Create the tables user, roles, permissions and their relationships
      */
     $capsule->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('name');
         $table->string('email')->unique();
         $table->string('password', 60);
         $table->rememberToken();
         $table->timestamps();
     });
     $capsule->schema()->create(\Config::get('permiso.roles_table'), function ($table) {
         $table->increments('id')->unsigned();
         $table->string('name')->unique();
         $table->string('display_name')->nullable();
         $table->string('description')->nullable();
         $table->timestamps();
     });
     $capsule->schema()->create(\Config::get('permiso.permissions_table'), function ($table) {
         $table->increments('id')->unsigned();
         $table->string('name')->unique();
         $table->string('display_name')->nullable();
         $table->string('description')->nullable();
         $table->timestamps();
     });
     $capsule->schema()->create(\Config::get('permiso.user_role_table'), function ($table) {
         $table->integer('user_id')->unsigned();
         $table->integer('role_id')->unsigned();
         $table->primary(array('user_id', 'role_id'));
         $table->foreign('user_id')->references('user_id')->on('users')->onUpdate('cascade')->onDelete('cascade');
         $table->foreign('role_id')->references('id')->on(\Config::get('permiso.roles_table'));
     });
     $capsule->schema()->create(\Config::get('permiso.role_permission_table'), function ($table) {
         $table->integer('role_id')->unsigned();
         $table->integer('permission_id')->unsigned();
         $table->primary(array('role_id', 'permission_id'));
         $table->foreign('role_id')->references('id')->on(\Config::get('permiso.roles_table'))->onUpdate('cascade')->onDelete('cascade');
         $table->foreign('permission_id')->references('id')->on(\Config::get('permiso.permissions_table'))->onUpdate('cascade')->onDelete('cascade');
     });
     /*
      * Seed the database
      */
     $user = new User();
     $user->name = "Admin";
     $user->email = '*****@*****.**';
     $user->password = "******";
     $user->save();
     $role = new \Riogo\Permiso\Role();
     $role->name = 'admin';
     $role = $user->roles()->save($role);
     $permission = new \Riogo\Permiso\Permission();
     $permission->name = 'user.delete';
     $role->permissions()->save($permission);
     $permission = new \Riogo\Permiso\Permission();
     $permission->name = 'user.list';
     $role->permissions()->save($permission);
 }
 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = new User();
     $user->username = '******';
     $user->display_name = 'Admin';
     $user->email = '*****@*****.**';
     $user->password = '******';
     $user->password_confirmation = 'admin';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = true;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageContent = new Permission();
     $manageContent->name = 'manage_contents';
     $manageContent->display_name = 'Manage Content';
     $manageContent->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageContent->id, $manageUsers->id]);
     $admin->perms()->sync([$manageContent->id]);
 }
Example #23
0
 public function main()
 {
     if (App::import('Component', 'AuthExt') && class_exists('AuthExtComponent')) {
         $this->Auth = new AuthExtComponent(new ComponentCollection());
     } else {
         App::import('Component', 'Auth');
         $this->Auth = new AuthComponent(new ComponentCollection());
     }
     while (empty($username)) {
         $username = $this->in(__('Username (2 characters at least)'));
     }
     while (empty($password)) {
         $password = $this->in(__('Password (2 characters at least)'));
     }
     $schema = $this->User->schema();
     if (isset($this->User->Role) && is_object($this->User->Role)) {
         $roles = $this->User->Role->find('list');
         if (!empty($roles)) {
             $this->out('');
             pr($roles);
         }
         $roleIds = array_keys($roles);
         while (!empty($roles) && empty($role)) {
             $role = $this->in(__('Role'), $roleIds);
         }
     } elseif (method_exists($this->User, 'roles')) {
         $roles = User::roles();
         if (!empty($roles)) {
             $this->out('');
             pr($roles);
         }
         $roleIds = array_keys($roles);
         while (!empty($roles) && empty($role)) {
             $role = $this->in(__('Role'), $roleIds);
         }
     }
     if (empty($roles)) {
         $this->out('No Role found (either no table, or no data)');
         $role = $this->in(__('Please insert a role manually'));
     }
     $this->out('');
     $pwd = $this->Auth->password($password);
     $data = array('User' => array('password' => $pwd, 'active' => 1));
     if (!empty($username)) {
         $data['User']['username'] = $username;
     }
     if (!empty($email)) {
         $data['User']['email'] = $email;
     }
     if (!empty($role)) {
         $data['User']['role_id'] = $role;
     }
     if (!empty($schema['status']) && method_exists('User', 'statuses')) {
         $statuses = User::statuses();
         pr($statuses);
         while (empty($status)) {
             $status = $this->in(__('Please insert a status'), array_keys($statuses));
         }
         $data['User']['status'] = $status;
     }
     if (!empty($schema['email'])) {
         $provideEmail = $this->in(__('Provide Email? '), array('y', 'n'), 'n');
         if ($provideEmail === 'y') {
             $email = $this->in(__('Please insert an email'));
             $data['User']['email'] = $email;
         }
         if (!empty($schema['email_confirmed'])) {
             $data['User']['email_confirmed'] = 1;
         }
     }
     $this->out('');
     $continue = $this->in(__('Continue? '), array('y', 'n'), 'n');
     if ($continue != 'y') {
         $this->error('Not Executed!');
     }
     $this->out('');
     $this->hr();
     if ($this->User->save($data)) {
         $this->out('User inserted! ID: ' . $this->User->id);
     } else {
         $this->error('User could not be inserted (' . print_r($this->User->validationErrors, true) . ')');
     }
 }
Example #24
0
 /**
  * UserShell::main()
  * //TODO: refactor (smaller sub-parts)
  *
  * @return void
  */
 public function main()
 {
     while (empty($username)) {
         $username = $this->in(__('Username (2 characters at least)'));
     }
     while (empty($password)) {
         $password = $this->in(__('Password (2 characters at least)'));
     }
     $schema = $this->User->schema();
     if (isset($this->User->Role) && is_object($this->User->Role)) {
         $roles = $this->User->Role->find('list');
         if (!empty($roles)) {
             $this->out('');
             $this->out(print_r($roles, true));
         }
         $roleIds = array_keys($roles);
         while (!empty($roles) && empty($role)) {
             $role = $this->in(__('Role'), $roleIds);
         }
     } elseif (method_exists($this->User, 'roles')) {
         $roles = User::roles();
         if (!empty($roles)) {
             $this->out('');
             $this->out(print_r($roles, true));
         }
         $roleIds = array_keys($roles);
         while (!empty($roles) && empty($role)) {
             $role = $this->in(__('Role'), $roleIds);
         }
     }
     if (empty($roles)) {
         $this->out('No Role found (either no table, or no data)');
         $role = $this->in(__('Please insert a role manually'));
     }
     $this->out('');
     $this->User->Behaviors->load('Tools.Passwordable', array('confirm' => false));
     //$this->User->validate['pwd']
     $data = array('User' => array('pwd' => $password, 'active' => 1));
     if (!empty($username)) {
         $usernameField = $this->User->displayField;
         $data['User'][$usernameField] = $username;
     }
     if (!empty($email)) {
         $data['User']['email'] = $email;
     }
     if (!empty($role)) {
         $data['User']['role_id'] = $role;
     }
     if (!empty($schema['status']) && method_exists('User', 'statuses')) {
         $statuses = User::statuses();
         $this->out(print_r($statuses, true));
         $status = $this->in(__('Please insert a status'), array_keys($statuses));
         $data['User']['status'] = $status;
     }
     if (!empty($schema['email'])) {
         $provideEmail = $this->in(__('Provide Email? '), array('y', 'n'), 'n');
         if ($provideEmail === 'y') {
             $email = $this->in(__('Please insert an email'));
             $data['User']['email'] = $email;
         }
         if (!empty($schema['email_confirmed'])) {
             $data['User']['email_confirmed'] = 1;
         }
     }
     $this->out('');
     $continue = $this->in(__('Continue?'), array('y', 'n'), 'n');
     if ($continue !== 'y') {
         return $this->error('Not Executed!');
     }
     $this->out('');
     $this->hr();
     if (!$this->User->save($data)) {
         return $this->error('User could not be inserted (' . print_r($this->User->validationErrors, true) . ')');
     }
     $this->out('User inserted! ID: ' . $this->User->id);
 }
 public function store()
 {
     $input = Input::all();
     $validation = Validator::make($input, User::$rules);
     if ($validation->passes()) {
         $user = new User();
         $user->email = Input::get('email');
         $user->username = Input::get('username');
         $user->password = Hash::make(Input::get('password'));
         $user->active = isset($input['active']) && $input['active'] ? 1 : 0;
         $user->save();
         $roles = array();
         foreach (explode(', ', Input::get('roles')) as $role_name) {
             if ($role = Role::where('role', '=', $role_name)->first()) {
                 $roles[] = $role->id;
             }
         }
         $user->roles()->sync($roles);
         Mail::send('emails.welcome', array('username' => $user->username), function ($message) use($user) {
             $message->to($user->email, $user->username)->subject(trans('login.welcome_subj'));
         });
         return Redirect::route('users.index');
     }
     return Redirect::route('users.create')->withInput()->withErrors($validation)->with('message', trans('validation.errors'));
 }
 function test_many_to_many_get_with_a_new_record()
 {
     $user = new User();
     $user_roles = $user->roles()->select();
     $this->assertCount(0, $user_roles, 'User should have zero roles');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->line('Lets start our migration.');
     //Migrate Groups to Roles
     $groups = DB::connection('oldmysql')->table('groups');
     $this->line($groups->count() . ' groups[\'s] were found in the legacy database');
     foreach ($groups->get() as $group) {
         $role = new Role();
         $role->name = $group->group;
         $role->save();
     }
     //Migrate Users
     $users = DB::connection('oldmysql')->table('users');
     $this->line($users->count() . ' user[\'s] were found in the legacy database');
     foreach ($users->get() as $user) {
         $this->line('Migrating user: '******'oldmysql')->table('groups')->where('id', $user->group)->first();
         $myrole = Role::where('name', $group->group)->first();
         $newuser->roles()->attach($myrole);
         $this->line('Adding user to role: ' . $group->group);
     }
     //Migrate Users
     $quotes = DB::connection('oldmysql')->table('quotes');
     $this->line($quotes->count() . ' quote[\'s] were found in the legacy database');
     foreach ($quotes->get() as $quote) {
         $this->line('Migrating quote: #' . $quote->id);
         $newquote = new Quote();
         $newquote->timestamps = false;
         $newquote->id = $quote->id;
         $newquote->title = $quote->title;
         $newquote->quote = $quote->quote;
         $user = User::find($quote->userid);
         $newquote->user()->associate($user);
         $newquote->status = $quote->approved;
         $newquote->created_at = date('Y-m-d H:i:s', $quote->timestamp);
         $newquote->updated_at = date('Y-m-d H:i:s', $quote->timestamp);
         $newquote->save();
     }
     $votes = DB::connection('oldmysql')->table('votes');
     $this->line($votes->count() . ' vote[\'s] were found in the legacy database');
     foreach ($votes->get() as $vote) {
         $user = User::find($vote->userid);
         $quote = Quote::find($vote->quoteid);
         if ($user && $quote) {
             if ($vote->vote == 1) {
                 $this->line($user->username . ' voted up #' . $quote->id);
             } else {
                 $this->line($user->username . ' voted down #' . $quote->id);
             }
             if ($quote) {
                 $vuser = $quote->voted()->whereUserId($vote->userid)->first();
                 if (!$vuser) {
                     $quote->voted()->attach($user, array('vote' => $vote->vote));
                 } else {
                     $vuser->pivot->vote = $vote->vote;
                     $vuser->pivot->save();
                 }
             }
             //Our confidence has changed in this quote.
             $quote->updateVoteConfidence();
         } else {
             if (!$quote) {
                 $this->line('Vote #' . $vote->id . ' could not be imported because the quote doesn\'t exist');
             }
             if (!$user) {
                 $this->line('Vote #' . $vote->id . ' could not be imported because the user doesn\'t exist');
             }
         }
     }
 }
Example #28
0
    print h($user->fullname);
    ?>
</a>
                </td>
                <td>
                    <a href="mailto:<?php 
    print h($user->email);
    ?>
"><?php 
    print h($user->email);
    ?>
</a>
                </td>
                <td>
                    <?php 
    print h(User::roles($user->role));
    ?>
                </td>
                <td>
                    <time datetime="<?php 
    print $user->created_at->format(DateTime::W3C);
    ?>
">
                        <?php 
    print datetime_to_s($user->created_at);
    ?>
                    </time>
                </td>
            </tr>
        <?php 
}
Example #29
0
 public function showUser(User $user)
 {
     $roles = $user->roles()->get();
     $this->layout->title = $user->username;
     $this->layout->main = View::make('users.dashboard', compact('user'))->nest('content', 'users.single', compact('user', 'roles'));
 }
Example #30
0
    ?>
</label>
                    <div class="col-lg-10">
                        <select id="user-role" class="form-control" name="user[role]" required>
                            <?php 
    if ($this->user->is_new_record()) {
        ?>
                                <option value=""><?php 
        print t("Choose a role for this user.");
        ?>
</option>
                            <?php 
    }
    ?>
                            <?php 
    foreach (User::roles() as $role_key => $role_to_s) {
        ?>
                                <option value="<?php 
        print h($role_key);
        ?>
" <?php 
        print $this->user->role === $role_key ? 'selected' : '';
        ?>
>
                                    <?php 
        print h($role_to_s);
        ?>
                                </option>
                            <?php 
    }
    ?>