/** * 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]); }
/** * 添加用户 * @return mixed */ public function store() { $user['email'] = $user['username'] = Input::get('email'); $user['password'] = Input::get('password0'); $mail_url = (new Uinfo())->getMail($user['email']); //判断用户是否存在 $user_exist = User::where('email', $user['email'])->first(); if ($user_exist) { return Redirect::back()->withErrors('邮箱已被占用!'); } $errors = ''; //添加用户 try { $user = Sentry::register($user); //添加默认用户组 $genealGroup = Sentry::findGroupById(2); $user->addGroup($genealGroup); //添加用户对应信息 Uinfo::create(['uid' => $user->id]); //登陆该用户 $data['activationCode'] = $user->getActivationCode(); $data['uid'] = $user->id; Mail::send('emails.auth.active', $data, function ($message) use($user) { $message->to($user->email, '尊敬的柚皮会员')->subject('欢迎注册柚皮网'); }); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $errors = '请输入完整注册信息.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $errors = '请输入密码.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { $errors = '用户已存在.'; } if ($errors) { return Redirect::back()->withErrors($errors); } else { return View::make('auth.active')->withEmail($mail_url); } }