Example #1
0
 /**
  * Handle creation a user.
  *
  * @return Response
  */
 public function create()
 {
     $statusCode = 200;
     $validationRules = array('email' => 'required|email', 'password' => 'required', 'group' => 'required', 'activated' => 'required', 'first_name' => 'required');
     // Do validation
     $validator = Validator::make(Input::all(), $validationRules);
     if (!$validator->fails()) {
         try {
             // Let's register a user.
             $user = Sentry::createUser(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name', ''), 'activated' => Input::get('activated')));
             // Find the group using the group id
             $group = Sentry::findGroupByName(Input::get('group'));
             // Assign the group to the user
             $user->addGroup($group);
             // Prepare the user data required
             $response = new UserTemplate($user);
             // Set status code
             $statusCode = 201;
         } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
             $response = array('message' => 'Provided information is not valid.', 'errors' => 'User with this login already exists.');
         } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
             $response = array('message' => 'Provided information is not valid.', 'errors' => 'Group was not found.');
             // Set status code
             $statusCode = 400;
         }
     } else {
         $response = array('message' => 'Provided information is not valid.', 'errors' => $validator->errors()->toArray());
     }
     return API::resourceJson($response, $statusCode);
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $email = $this->argument('email');
     $password = $this->argument('password', 'admin123');
     $firstName = $this->argument('first_name', 'Admin');
     $lastName = $this->argument('last_name', 'Tea');
     if (empty($email)) {
         $email = '*****@*****.**';
     }
     if (empty($password)) {
         $password = '******';
     }
     if (empty($firstName)) {
         $firstName = 'Admin';
     }
     if (empty($lastName)) {
         $lastName = 'Tea';
     }
     try {
         // Let's register a user.
         $user = Sentry::createUser(array('email' => $email, 'password' => $password, 'first_name' => $firstName, 'last_name' => $lastName, 'activated' => true));
         // Find the group using the group id
         $group = Sentry::findGroupByName('Administrators');
         // Assign the group to the user
         $user->addGroup($group);
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         $this->error('User with this login already exists');
     } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         $this->error('Group was not found');
     }
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Get validation rules
     $rules = $this->user->{$rules};
     // Set password confirmation rule
     $rules['password'] .= '|confirmed';
     $validator = Validator::make(Input::all(), $rules);
     if (!$validator->fails()) {
         try {
             $user = Sentry::createUser(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')));
             // Activate user
             $user->attemptActivation($user->getActivationCode());
             if (Input::has('superuser')) {
                 $user->superuser = Input::get('superuser');
             }
             $user->groups = Input::get('groups');
             if (Input::get('notify')) {
                 // Send notifcation email
                 $loginLink = $user->hasAccess('admin') ? URL::to('admin/login') : URL::to('login');
                 $mailData = array('user' => $user, 'password' => Input::get('password'), 'loginLink' => $loginLink);
                 Mail::queue(array('emails.admin.newuser', 'emails.admin.newuser_text'), $mailData, function ($message) use($user) {
                     $message->to($user->email, $user->first_name . ' ' . $user->last_name)->subject('Huurd.it - User account created');
                 });
             }
             Session::flash('success', 'User added');
             return Redirect::to('admin/users');
         } catch (Exception $e) {
             Session::flash('error', $e->getMessage());
         }
     }
     Input::flash();
     return Redirect::to('admin/users/create')->withErrors($validator);
 }
 public function create(array $attributes)
 {
     try {
         $user = Sentry::createUser(array('email' => $attributes['email'], 'password' => $attributes['password'], 'activated' => true));
         $adminGroup = Sentry::findGroupById($attributes['group_id']);
         $user->addGroup($adminGroup);
         return $user;
     } catch (\Exception $e) {
     }
 }
Example #5
0
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function postStore()
 {
     $user = Sentry::createUser(Input::all());
     //添加默认用户组
     $genealGroup = Sentry::findGroupById(2);
     $user->addGroup($genealGroup);
     if ($user) {
         return Response::json(['status' => 1]);
     } else {
         return Response::json(['status' => 0]);
     }
 }
 /**
  * Create a user through Sentry and add the groups specified to the user
  * if they exist.
  *
  * @param array  $data
  * @param array  $groups
  * @param bool   $activated
  *
  * @return mixed
  */
 public function createUser(array $data, array $groups = [], $activated = true)
 {
     try {
         $insert = ['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'username' => $data['username'], 'password' => $data['password'], 'activated' => $activated];
         $user = Sentry::createUser($insert);
         $this->addGroupsToUser($user, $groups);
     } catch (UserExistsException $e) {
         $loginAttribute = config('cartalyst.sentry.users.login_attribute');
         $user = Sentry::findUserByLogin($data[$loginAttribute]);
     }
     return $user;
 }
Example #7
0
 /**
  * Create a user and assign roles to it
  * @param array $data
  * @param array $roles
  * @param bool  $activated
  */
 public function createWithRoles($data, $roles, $activated = false)
 {
     $user = Sentry::createUser(array_merge($data, ['activated' => $activated]));
     $user->activated = $activated ? 1 : 0;
     $user->save();
     if (!empty($roles)) {
         foreach ($roles as $roleId) {
             $group = Sentry::findGroupById($roleId);
             $user->addGroup($group);
         }
     }
 }
 public function run()
 {
     User::truncate();
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 10; $i++) {
         try {
             // Create the user
             $user = Sentry::createUser(array('first_name' => $faker->name, 'last_name' => $faker->name, 'email' => $faker->unique()->email, 'phone' => $faker->unique()->phoneNumber, 'image_url' => $faker->imageUrl($width = 640, $height = 480), 'password' => '123', 'activated' => true));
             // Find the group using the group id
             $adminGroup = Sentry::findGroupById($faker->randomElement(array(1, 2, 3)));
             // Assign the group to the user
             $user->addGroup($adminGroup);
         } catch (\Exception $e) {
         }
     }
 }
 public function signup()
 {
     $input = Input::all();
     $rules = array('password' => array('required', 'min:6'), 'email' => 'required|email');
     $validation = Validator::make(Input::all(), $rules);
     //check
     $objUsers = new Users();
     $check = $objUsers->where('email', '=', trim(strtolower($input['email'])))->count();
     if ($validation->fails() || $check > 0) {
         $messages = '';
         if ($check > 0) {
             $messages .= 'User with this email already exists. ';
         }
         $mess = $validation->errors()->getMessages();
         foreach ($mess as $v) {
             $messages .= $v[0] . ' ';
         }
         if ($messages != '') {
             Session::flash('message', $messages);
         }
         return Response::json(0);
     } else {
         try {
             $datacreateUser = array('email' => trim(strtolower($input['email'])), 'password' => isset($input['password']) ? $input['password'] : '', 'activated' => true, 'first_name' => isset($input['first_name']) ? $input['first_name'] : '', 'last_name' => isset($input['last_name']) ? $input['last_name'] : '');
             $user = Sentry::createUser($datacreateUser);
             Sentry::authenticate(array('email' => trim(strtolower($input['email'])), 'password' => isset($input['password']) ? $input['password'] : ''));
             /*Mail::send('system::email.email_template.acount_info', $input, function($message) use ($email, $first_name) {
                   $message->to($email, $first_name)->subject('Welcome to the Tastable.net');
               });*/
         } catch (LoginRequiredException $e) {
             Session::flash('message', 'Login field is required. ');
             return Response::json(0);
         } catch (PasswordRequiredException $e) {
             Session::flash('message', 'Password field is required. ');
             return Response::json(0);
         } catch (UserExistsException $e) {
             Session::flash('message', 'User with this email already exists. ');
             return Response::json(0);
         }
     }
     Session::flash('message', 'User created');
     return Response::json(1);
 }
Example #10
0
 /**
  * Create user with given credentials
  *
  * @param array $user
  * @return \Cartalyst\Sentry\Users\UserInterface|false
  */
 public function create(array $user)
 {
     try {
         $user = Sentry::createUser($user);
     } catch (LoginRequiredException $e) {
         $this->error = 'Email field is required.';
         return false;
     } catch (PasswordRequiredException $e) {
         $this->error = 'Password field is required.';
         return false;
     } catch (UserExistsException $e) {
         $this->error = 'User with this login already exists.';
         return false;
     } catch (GroupNotFoundException $e) {
         $this->error = 'Group was not found.';
         return false;
     }
     return $user;
 }