/**
  * 生成找回密码token,存数据库
  * @param $token
  * @return bool
  */
 public function createToken($email, $token)
 {
     $user = new User();
     if (!$user->checkNotLocked($email)) {
         return false;
     }
     $this->deleteToken($email);
     $this->email = $email;
     $this->token = $token;
     $this->created_at = Carbon::now();
     return $this->save();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     // seed Location
     foreach (range(0, 3) as $index) {
         $name = ['Banner', 'Privilege', 'ClickChannel', 'ShopOfTheWeek'];
         $width = [580, 640, 700];
         $height = [420, 480, 540];
         // $parentID = (Location::count() > 0)? Location::orderByRaw('RAND()')->first()->id : 0;
         $location = Location::create(['user_id' => User::orderByRaw('RAND()')->first()->id, 'location_name' => $name[$index], 'limit' => rand(1, 20), 'width' => $width[rand(0, count($width) - 1)], 'height' => $height[rand(0, count($height) - 1)], 'sort_order' => 1, 'flag_last' => $index ? 1 : 0, 'types' => $index + 1, 'status' => rand(0, 1)]);
         if ($index == 0) {
             foreach (range(1, 7) as $sub_index) {
                 Location::create(['user_id' => User::orderByRaw('RAND()')->first()->id, 'location_name' => $name[$index] . ' sub' . $sub_index, 'limit' => 1, 'width' => $width[rand(0, count($width) - 1)], 'height' => $height[rand(0, count($height) - 1)], 'sort_order' => $sub_index, 'flag_last' => $sub_index == 7 ? 1 : 0, 'types' => $index + 1, 'status' => 1]);
             }
         }
     }
     // seed PageContent
     foreach (range(0, 60) as $index) {
         $location = Location::orderByRaw('RAND()')->first();
         $sortOrder = $location->pageContents->count() > 0 ? $location->pageContents->count() + 1 : 1;
         $date = new DateTime();
         $date_start = $date->format('Y-m-d');
         $date->modify('+' . rand(1, 10) . ' day');
         $date_end = $date->format('Y-m-d');
         PageContent::create(['location_id' => $location->id, 'user_id' => User::orderByRaw('RAND()')->first()->id, 'name' => $faker->userName, 'link_url' => $faker->url, 'image_url' => $faker->imageUrl($width = $location->width, $height = $location->height), 'parent_id' => 0, 'sort_order' => $sortOrder, 'start' => $date_start, 'end' => $date_end, 'status' => rand(0, 1)]);
     }
 }
 public function set_perm($id)
 {
     $user = User::find($id);
     $validator = Validator::make(Request::all(), ['perm' => 'required']);
     if ($validator->fails()) {
         return back()->withErrors($validator)->withInput();
     }
     $user->set_value_by_key('perm', Request::input('perm'));
     return redirect()->action('Admin\\UserController@index');
 }
Exemple #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     // seed group_user
     foreach (range(1, 6) as $index) {
         GroupUser::create(['group_name' => $faker->safeColorName, 'sort_order' => $index, 'status' => rand(0, 1)]);
     }
     // seed user
     $group_user = GroupUser::all();
     foreach (range(0, 20) as $index) {
         User::create(['group_id' => $group_user->shuffle()->first()->id, 'username' => 'test' . $index . '@col.com', 'password' => Hash::make('1234'), 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'position' => $faker->companySuffix, 'department' => $faker->company, 'status' => $index == 0 ? 1 : rand(0, 1)]);
     }
 }
 /**
  * Get authority menus
  *
  * @return array
  */
 public function getMenus()
 {
     $menus = array();
     $accountId = Auth::user()->id;
     $user = User::find($accountId);
     $authorityMenus = $user->getAuthorityMenus;
     $authMenus = explode(',', $authorityMenus->menuIds);
     if ($user->menu == 'all') {
         $menus = $authMenus;
     } else {
         $userMenus = explode(',', $user->menu);
         $menus = array_intersect($userMenus, $authMenus);
     }
     return $menus;
 }
 public function index($uid = 0)
 {
     Debugbar::disable();
     //$user = User::find($uid);
     $perm = [];
     if ($uid) {
         $user = User::find($uid);
         $perm = $user->perm;
         if (!$perm) {
             $perm = [];
         }
     } else {
         //$user = new User;
     }
     $perms = Term::get_item_by_type('permission');
     //print_this($perms);
     //print_this($perm);
     return view('perm.perm', ['perms' => $perms, 'has_perm' => $perm]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  App\Http\Requests\Admin\LoginRequest  $request
  * @return \Illuminate\Http\Response
  */
 public function store(LoginRequest $request)
 {
     $getData = User::where('username', e($request->input('username')))->get();
     if (isset($getData[0])) {
         if ($getData[0]->status == 1) {
             if (Hash::check($request->input('password'), $getData[0]->password)) {
                 $setSession['id'] = $getData[0]->id;
                 $setSession['username'] = $getData[0]->username;
                 $setSession['first_name'] = $getData[0]->first_name;
                 $setSession['last_name'] = $getData[0]->last_name;
                 $request->session()->put('backoffice', $setSession);
                 return redirect()->action('Admin\\DashboardController@index');
             } else {
                 $MessageShow = trans('banner_messages.passwordFail');
             }
         } else {
             $MessageShow = trans('banner_messages.statusUserNoneActive');
         }
     } else {
         $MessageShow = trans('banner_messages.nodataInSyatem');
     }
     $setData['errorMsg'] = $MessageShow;
     return View::make('admin.login.index', $setData);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(int $id) : int
 {
     return User::find($id)->delete();
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }