示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = array("email" => Input::get("email"), "first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "password" => Input::get("password"), "repassword" => Input::get("repassword"), "groups" => Input::get("groups") == null ? array() : Input::get("groups"));
     $rules = array("email" => "required|unique:users,email", "first_name" => "required", "last_name" => "required", "password" => "required|min:6", "repassword" => "required|min:6|same:password");
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         return Redirect::route('admin.users.create')->withErrors($validator)->withInput();
     } else {
         $user = new AdminUser();
         $user->email = $data['email'];
         $user->first_name = $data['first_name'];
         $user->last_name = $data['last_name'];
         $user->password = Hash::make($data['password']);
         if ($user->save()) {
             $s_user = Sentry::findUserById($user->id);
             foreach ($data["groups"] as $group) {
                 $s_user->addGroup(Sentry::findGroupById($group));
             }
             Session::flash('success', "Đã thêm user" . $data['email'] . " thành công");
             return Redirect::route('admin.users.create');
         } else {
             Session::flash('error', "Xảy ra lỗi trong khi thêm user " . $data['name']);
             return Redirect::route('admin.users.create');
         }
     }
 }
 public function update($id, array $attributes)
 {
     try {
         // Find the user using the user id
         $user = Sentry::findUserById($id);
         $group_id = 0;
         foreach ($user->groups as $group) {
             $group_id = $group->id;
         }
         if ($group_id > 0 && $group_id != $attributes['group_id']) {
             // User is  Assigned , So Remove Old Group and Re-assigned New Group
             // Find Old the group using the group id
             $oldGroup = Sentry::findGroupById($group_id);
             $user->removeGroup($oldGroup);
             // Find New the group using the group id
             $newGroup = Sentry::findGroupById($attributes['group_id']);
             $user->addGroup($newGroup);
         } else {
             if ($group_id == 0 && $attributes['group_id'] > 0) {
                 // User is Not Assigned , So Assigned New Group
                 // Find New the group using the group id
                 $newGroup = Sentry::findGroupById($attributes['group_id']);
                 $user->addGroup($newGroup);
             }
         }
         $user->email = $attributes['email'];
         $user->save();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
示例#3
0
 public static function getUser($id = 0)
 {
     if ($id == 0) {
         return Sentry::getUser();
     } else {
         return Sentry::findUserById($id);
     }
 }
示例#4
0
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIndex()
 {
     $posts = $this->post->all();
     foreach ($posts as $k => $v) {
         $posts[$k]['author'] = Sentry::findUserById($v->uid)->username;
     }
     return Response::json($posts);
 }
示例#5
0
 /**
  * Activate the given used id
  * @param  int    $userId
  * @param  string $code
  * @return bool
  */
 public function activate($userId, $code)
 {
     $user = Sentry::findUserById($userId);
     try {
         return $user->attemptActivation($code);
     } catch (\Exception $e) {
         return false;
     }
 }
示例#6
0
 public function index()
 {
     $app_id = Config::get('registration::social.fb.api_id');
     $app_secret = Config::get('registration::social.fb.secret_key');
     $my_url = "http://" . $_SERVER['HTTP_HOST'] . "/auth_soc/face_res";
     $code = Input::get("code");
     $state = Input::get("state");
     if (empty($code)) {
         Session::put('state', md5(uniqid(rand(), TRUE)));
         $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=public_profile,publish_actions,email&state=" . Session::get('state') . "&fields=email,first_name,last_name,id,gender";
         header("Location: {$dialog_url}");
     }
     if ($state == Session::get('state')) {
         $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code . "&fields=email,first_name,last_name,id,gender";
         $response = file_get_contents($token_url);
         $params = null;
         parse_str($response, $params);
         $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token'] . "&fields=email,first_name,last_name,id,gender";
         $user = json_decode(file_get_contents($graph_url));
         $first_name = $user->first_name;
         $last_name = $user->last_name;
         $fb_id = $user->id;
         if (isset($user->email)) {
             $user_email = $user->email;
         } else {
             $user_email = $fb_id;
         }
         //проверка юзера
         if ($user_email && $fb_id) {
             $user = DB::table("users")->where("id_fb", $fb_id)->first();
             if (!$user['id']) {
                 $user = DB::table("users")->where("email", "like", $user_email)->first();
             }
             if (!$user['id']) {
                 $new_pass = str_random(6);
                 $user = Sentry::register(array('email' => $user_email, 'password' => $new_pass, 'id_fb' => $fb_id, 'activated' => "1", 'first_name' => $first_name, 'last_name' => $last_name));
                 $user_auth = Sentry::findUserById($user->id);
                 Sentry::login($user_auth, Config::get('registration::social.fb.remember'));
             } else {
                 $user_auth = Sentry::findUserById($user['id']);
                 Sentry::login($user_auth, Config::get('registration::social.fb.remember'));
             }
             $redirect = Session::get('url_previous', "/");
             Session::forget('url_previous');
             //if not empty redirect_url
             if (Config::get('registration::social.fb.redirect_url')) {
                 $redirect = Config::get('registration::social.fb.redirect_url');
                 Session::flash('id_user', $user_auth->id);
             } else {
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
             }
             return Redirect::to($redirect);
         }
     }
 }
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIndex()
 {
     $status = Input::get('type');
     $shops = $this->shop->where('status', '=', $status)->paginate(1);
     foreach ($shops as $k => $v) {
         $shops[$k]['category'] = $this->category->find($v->category_id)->name;
         $shops[$k]['user'] = Sentry::findUserById($v->user_id)->username;
     }
     return Response::json($shops);
 }
示例#8
0
 public function index()
 {
     if (Input::get("code")) {
         $api_id = Config::get('registration::social.vk.api_id');
         $secret_key = Config::get('registration::social.vk.secret_key');
         $params = array('client_id' => $api_id, 'client_secret' => $secret_key, 'code' => Input::get("code"), 'redirect_uri' => "http://" . $_SERVER['HTTP_HOST'] . "/auth_soc/vk_res");
         $url = 'https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params));
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $result = curl_exec($ch);
         curl_close($ch);
         $data = json_decode($result, true);
         if (isset($data['access_token'])) {
             $str = "https://api.vkontakte.ru/method/getProfiles?uid=" . $data['user_id'] . "&fields=photo_big&access_token=" . $data['access_token'];
             $resp2 = file_get_contents($str);
             $el = json_decode($resp2, true);
             $first_name = $el['response'][0]['first_name'];
             $last_name = $el['response'][0]['last_name'];
             $id_user = $el['response'][0]['uid'];
             $user = DB::table("users")->where("id_vk", $id_user)->first();
             if (!isset($user['id'])) {
                 $new_pass = str_random(6);
                 $user = Sentry::register(array('email' => $id_user, 'password' => $new_pass, 'id_vk' => $id_user, 'activated' => "1", 'first_name' => $first_name, 'last_name' => $last_name));
                 //качаем аватарку юзера
                 if ($el['response'][0]['photo_big'] && Config::get('registration::social.vk.foto')) {
                     $id_one = substr($user->id, 0, 1);
                     $destinationPath = "/storage/users/{$id_one}/{$user->id}/";
                     $path_server = public_path() . $destinationPath;
                     File::makeDirectory($path_server, $mode = 0777, true, true);
                     $foto_resource = file_get_contents($el['response'][0]['photo_big']);
                     $foto_user = time() . basename($el['response'][0]['photo_big']);
                     $f = fopen($_SERVER['DOCUMENT_ROOT'] . $destinationPath . $foto_user, 'w');
                     fwrite($f, $foto_resource);
                     fclose($f);
                     $user->photo = $destinationPath . $foto_user;
                     $user->save();
                 }
                 $user_auth = Sentry::findUserById($user->id);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             } else {
                 $user_auth = Sentry::findUserById($user['id']);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             }
             //if not empty redirect_url
             if (Config::get('registration::social.vk.redirect_url')) {
                 $redirect = Config::get('registration::social.vk.redirect_url');
                 Session::flash('id_user', $user_auth->id);
             } else {
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
             }
             return Redirect::to($redirect);
         }
     }
 }
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIndex()
 {
     $status = Input::get('type');
     $shops = $this->shop->select('id', 'title', 'category_id', 'thumb', 'user_id', 'price', 'comments', 'hits', 'created_at', 'updated_at')->where('status', '=', $status)->with(array('images' => function ($query) {
         $query->select('id', 'path');
     }))->paginate(15);
     foreach ($shops as $k => $v) {
         $shops[$k]['category'] = $this->category->find($v->category_id)->name;
         $shops[$k]['user'] = Sentry::findUserById($v->user_id)->username;
     }
     return Response::json($shops);
 }
示例#10
0
 public function showUser($id)
 {
     $currentUser = Sentry::getUser();
     $user = Sentry::findUserById($id);
     if ($user) {
         $allGroups = Sentry::findAllGroups();
         $hasPower = Permission::hasPower($user, $currentUser);
         return view('admin.edituser')->with('currentUser', $currentUser)->with('user', $user)->with('allGroups', $allGroups)->with('hasPower', $hasPower);
     } else {
         echo "User not found.";
     }
 }
示例#11
0
 /**
  * Activate the given used id
  * @param  int    $userId
  * @param  string $code
  * @return bool
  */
 public function activate($userId, $code)
 {
     $user = Sentry::findUserById($userId);
     try {
         $success = $user->attemptActivation($code);
         if ($success) {
             event(new UserHasActivatedAccount($user));
         }
         return $success;
     } catch (\Exception $e) {
         return false;
     }
 }
示例#12
0
 public function show($id)
 {
     $user = Sentry::findUserById($id);
     if ($user == null || !is_numeric($id)) {
         // @codeCoverageIgnoreStart
         return \App::abort(404);
         // @codeCoverageIgnoreEnd
     }
     $isOwner = $this->profileOwner($id);
     if ($isOwner !== true) {
         return $isOwner;
     }
     return View::make('Sentinel::users.show')->with('user', $user);
 }
 public function oauth2callback()
 {
     if (Input::get("code")) {
         $params = array('client_id' => Config::get('registration::social.google.api_id'), 'client_secret' => Config::get('registration::social.google.secret_key'), 'redirect_uri' => Config::get('registration::social.google.redirect_oauth2callback'), 'grant_type' => 'authorization_code', 'code' => Input::get("code"));
         $url = 'https://accounts.google.com/o/oauth2/token';
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         $result = curl_exec($curl);
         curl_close($curl);
         $tokenInfo = json_decode($result, true);
         if (isset($tokenInfo['access_token'])) {
             $params['access_token'] = $tokenInfo['access_token'];
             $userInfo = json_decode(file_get_contents('https://www.googleapis.com/oauth2/v1/userinfo' . '?' . urldecode(http_build_query($params))), true);
             if ($userInfo["id"]) {
                 $email = trim($userInfo['email']);
                 $user = DB::table("users")->where("email", "like", $email)->first();
                 if (!$user['id']) {
                     $new_pass = str_random(6);
                     $user = Sentry::register(array('email' => $email, 'password' => $new_pass, 'activated' => "1", 'first_name' => $userInfo['given_name'], 'last_name' => $userInfo['family_name']));
                     $user_auth = Sentry::findUserById($user->id);
                     Sentry::login($user_auth, Config::get('registration::social.google.remember'));
                 } else {
                     $user_auth = Sentry::findUserById($user['id']);
                     Sentry::login($user_auth, Config::get('registration::social.google.remember'));
                 }
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
                 //if not empty redirect_url
                 if (Config::get('registration::social.google.redirect_url')) {
                     $redirect = Config::get('registration::social.google.redirect_url');
                     Session::flash('id_user', $user_auth->id);
                 } else {
                     $redirect = Session::get('url_previous', "/");
                     Session::forget('url_previous');
                 }
                 return Redirect::to($redirect);
             }
         }
     }
 }
示例#14
0
 /**
  * Handle delete a user.
  *
  * @param  integer $userId
  * @return Response
  */
 public function delete($userId)
 {
     try {
         $user = Sentry::findUserById($userId);
     } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
         // Return 404 if user not found
         return API::resourceJson(array('message' => 'Requested user could not be found.'), 404);
     }
     if (!$user->delete()) {
         return API::resourceJson(array('message' => 'Unable to delete the user.'), 500);
     }
     return Response::make('', 204);
 }
示例#15
0
 /**
  * @param $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function deleteDestroy($id)
 {
     $user = Sentry::findUserById($id);
     $status = $user->delete() ? 1 : 0;
     return Response::json(['status' => $status]);
 }
 /**
  * 用户组添加成员
  * @param $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function putAddMemberToGroup($id)
 {
     $group = Sentry::findGroupById($id);
     $errors = '';
     foreach (Input::all() as $user) {
         if ($user['checked']) {
             $member = Sentry::findUserById($user['id']);
             if (!$member->addGroup($group)) {
                 $errors = true;
             }
         }
     }
     return Response::json(['status' => $errors ? 0 : 1]);
 }
示例#17
0
 /**
  * Remove user by ID.
  *
  * @param int $id
  * @return bool
  */
 public function delete($id)
 {
     try {
         $user = Sentry::findUserById($id);
         $user->delete();
     } catch (UserNotFoundException $e) {
         $this->error = 'User was not found.';
         return false;
     }
     return true;
 }
示例#18
0
 public function resetpass($uid, $code)
 {
     try {
         $user = Sentry::findUserById($uid);
         if ($user->checkResetPasswordCode($code)) {
             if (Request::isMethod('get')) {
                 return View::make('auth.resetpass');
             } else {
                 //判断两次密码输入是否一致
                 if (strpos(Input::get('password'), Input::get('repass')) === false) {
                     return Response::json(['status' => false, 'msg' => '两次密码输入不正确!']);
                 }
                 //重设密码
                 if ($user->attemptResetPassword($code, Input::get('password'))) {
                     return Response::json(['status' => true, 'msg' => '密码重置成功!']);
                 } else {
                     return Response::json(['status' => false, 'msg' => '密码重置失败,请重试!']);
                 }
             }
         } else {
             return Redirect::route('auth.forgetpass')->withErrors('验证数据错误,请重新验证!');
         }
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         return Redirect::route('auth.forgetpass')->withErrors('验证数据错误,用户不存在,请重新验证!');
     }
 }
 public function changstatususer()
 {
     $input = Input::all();
     $user = Sentry::findUserById($input['id']);
     $user->activated = $input['activated'];
     if ($user->save()) {
         $throttle = Sentry::findThrottlerByUserId($input['id']);
         if ($input['activated'] == 0) {
             $throttle->ban();
         } else {
             $throttle->unBan();
         }
         Response::json('1');
     } else {
         Response::json('0');
     }
 }
示例#20
0
 public function handleDeleteRow($id)
 {
     $user = Sentry::findUserById($id);
     $user->delete();
     return array('id' => $id, 'status' => true);
 }
示例#21
0
 /**
  * Find a user through Sentry by their ID.
  *
  * @param string|int $id
  *
  * @return bool|mixed
  */
 public function findUserById($id)
 {
     try {
         $user = Sentry::findUserById($id);
         return $user;
     } catch (UserNotFoundException $e) {
         return false;
     }
 }
示例#22
0
 /**
  * Deletes a user
  * @param $id
  * @return mixed
  * @throws UserNotFoundException
  */
 public function delete($id)
 {
     if ($user = Sentry::findUserById($id)) {
         return $user->delete();
     }
     throw new UserNotFoundException();
 }