상속: extends App\Http\Controllers\Controller, use trait Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers
예제 #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         $auth = new AuthController();
         return redirect($auth->getRedirectPath());
     }
     return $next($request);
 }
예제 #2
0
 public function index()
 {
     if (!Auth::check()) {
         $auth = new AuthController();
         return $auth->getLogin();
     }
     return redirect()->intended('dashboard');
 }
 public function register(Request $request)
 {
     $email = $request->input('email');
     $password = $request->input('password');
     $user = array('email' => $email, 'password' => $password, 'name' => $email);
     $object = new AuthController();
     $newUser = $object->create($user);
     return Response::json(array('result' => $newUser));
 }
예제 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param AuthController $auth
  * @internal param Request $request
  * @return Response
  */
 public function store(AuthController $auth)
 {
     $data = Input::all();
     $valid = $auth->validator($data);
     if ($valid->fails()) {
         return redirect()->back()->withInput()->withErrors($valid);
     }
     $user = $auth->create($data);
     Auth::login($user);
     return redirect()->to('admin');
 }
 public function create(Request $request)
 {
     // $result = $this->tokensMatch($request);
     // return Response::json(array('result' => $result ));
     $email = $request->input('email');
     $password = $request->input('password');
     $status = $request->input('status');
     $user = array('email' => $email, 'password' => $password, 'name' => $email, 'status' => $status);
     $object = new AuthController();
     $newUser = $object->create($user);
     return Response::json(array('result' => true, 'data' => $newUser));
 }
예제 #6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             $auth = new AuthController();
             return redirect($auth->getLoginPath());
         }
     }
     return $next($request);
 }
예제 #7
0
 /**
  * Store a new school.
  *
  * @param AddSchoolFormRequest $request
  * @return Response
  */
 public function addSchool(AddSchoolFormRequest $request)
 {
     $school = School::create(['name' => $request->school, 'town_id' => $request->town]);
     $user = new AuthController();
     $data = $request->all();
     $data['class'] = -1;
     $data['role'] = 1;
     $data['school'] = $school->id;
     $data['is_moderated'] = 1;
     $user->create($data);
     return redirect(route('home'));
 }
예제 #8
0
 /**
  * 登录页面
  */
 public function login(Request $request)
 {
     $viewData = [];
     if ($request->method() == 'POST') {
         $auth = new AuthController();
         $result = $auth->loginVerify($request->all());
         if ($result === true) {
             return redirect('/');
         }
         $this->viewData['error'] = $result;
     }
     return view('login', $this->viewData);
 }
예제 #9
0
 public function index()
 {
     if (!AuthController::checkPermission()) {
         return redirect('/auth/login')->with('redirectPath', '/admin');
     }
     return CoursesController::viewAllCourses();
 }
예제 #10
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $s = Subquestions::find($id);
     if (count($s) < 1) {
         return redirect('/');
     }
     $answers = Answers::where('SubQuestionID', '=', $id)->delete();
     $s->delete();
 }
예제 #11
0
 public static function destroy($SpaceID)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $space = Spaces::find($SpaceID);
     $answers = Answers::where('SpaceID', '=', $SpaceID)->get()->toArray();
     foreach ($answers as $answer) {
         Answers::destroy($answer['id']);
     }
     $space->delete();
     return;
 }
예제 #12
0
 /**
  * Register user
  * @param Request $request
  * @return token
  */
 public function postRegister(Request $request)
 {
     $validator = AuthController::validator($request->all());
     if ($validator->fails()) {
         return response()->json(['Email is already registered / Something wrong with input.'], 403);
     }
     //create user
     $user = AuthController::create($request->all());
     //credentials for login
     $credentials = $request->only('email', 'password');
     $token = $this->loginUser($credentials);
     return response()->json(compact('token'));
 }
예제 #13
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //dd($request);
     $password = $request->get('password');
     $username = $request->get('username');
     echo $username;
     echo $password;
     $attempt = Auth\AuthController::attempt(['username' => $username, 'password' => $password]);
     if ($attempt) {
         echo "pumasok";
     } else {
         echo "error";
     }
 }
예제 #14
0
 public function login()
 {
     $response = array("success" => false, "user" => null, "message" => "");
     $jsonString = Input::get("password");
     //TODO hide secret passphrase in .ENV or so
     $passphrase = "secret";
     $jsondata = json_decode($jsonString, true);
     try {
         $salt = hex2bin($jsondata["s"]);
         $iv = hex2bin($jsondata["iv"]);
     } catch (Exception $e) {
         return null;
     }
     $ct = base64_decode($jsondata["ct"]);
     $concatedPassphrase = $passphrase . $salt;
     $md5 = array();
     $md5[0] = md5($concatedPassphrase, true);
     $result = $md5[0];
     for ($i = 1; $i < 3; $i++) {
         $md5[$i] = md5($md5[$i - 1] . $concatedPassphrase, true);
         $result .= $md5[$i];
     }
     $key = substr($result, 0, 32);
     $data = openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
     if (Auth::attempt(['name' => Input::get("nameOrEmail"), 'password' => json_decode($data, true)]) || Auth::attempt(['email' => Input::get("nameOrEmail"), 'password' => json_decode($data, true)])) {
         $response['success'] = true;
         $response['user']["id"] = Auth::user()->id;
         $response['user']["name"] = Auth::user()->name;
         $response['user']["role"] = Auth::user()->role;
         $response['user']["has_subscribed"] = Auth::user()->has_subscribed;
         \App\Http\Controllers\Auth\AuthController::transferCookie();
     } else {
         $response['message'] = "geen correct gegevens";
     }
     return $response;
 }
예제 #15
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $course = Courses::find($id);
     $posts = Posts::where('CourseID', '=', $id)->get()->toArray();
     //        dd($posts);
     foreach ($posts as $post) {
         PostsController::destroy($post['id']);
         //            dd($post['id']);
     }
     $course->delete();
     return redirect(route('admin'));
 }
예제 #16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     // return redirect('/');
     $answer = Answers::find($id);
     if (count($answer) < 1) {
         return redirect('/');
     }
     @unlink(public_path('images/imageAnswer/' . $answer['Photo']));
     $answer->delete();
 }
예제 #17
0
"><a href="<?php 
echo url('despre');
?>
">Despre Noi</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <?php 
if (Auth::check()) {
    ?>
                    <li class="navbar-text"><?php 
    echo Auth::user()->firstname, ' ', Auth::user()->lastname;
    ?>
</li>
                    <li><a href="<?php 
    echo Controllers\Auth\AuthController::action('getLogout');
    ?>
">Logout</a></li>
                <?php 
} else {
    ?>
                    <li><a href="<?php 
    echo Controllers\Auth\AuthController::action('getLogin');
    ?>
">Login</a></li>
                <?php 
}
?>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
예제 #18
0
 public function addUserTags()
 {
     $request = Request::capture();
     $token = $request->input('token');
     $tags = $request->input('tags');
     if ($tags == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_Error, '', '标签不能为空');
     }
     $userId = AuthController::getUserIdByToken($token);
     if ($userId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败');
     }
     DB::beginTransaction();
     try {
         $array = explode(',', $tags);
         $result = UserTags::where('user_id', $userId)->delete();
         foreach ($array as $tag) {
             $result = UserTags::create(['user_id' => $userId, 'tag_id' => $tag]);
         }
         DB::commit();
         return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, '', '添加成功');
     } catch (Exception $e) {
         DB::rollBack();
         return Utility::response_format(Utility::RESPONSE_CODE_DB_ERROR, '', $e->getMessage());
     }
 }
예제 #19
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = $question['FormatID'];
     switch ($format) {
         case 1:
         case 6:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 2:
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
             break;
         case 3:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 4:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 5:
             $subq = Subquestions::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($subq as $s) {
                 SubquestionsController::destroy($s['id']);
             }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }
예제 #20
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     // return redirect('/');
     $s = Subquestions::find($id);
     if (count($s) < 1) {
         return redirect('/');
     }
     $answers = Answers::where('SubQuestionID', '=', $id)->get()->toArray();
     foreach ($answers as $a) {
         AnswersController::destroy($a['id']);
     }
     @unlink(public_path('images/imageSubquestion/' . $s['Photo']));
     $s->delete();
 }
예제 #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $answer = Answers::find($id);
     $answer->delete();
 }
예제 #22
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $post = Posts::find($id);
     @unlink(public_path('images/imagePost/' . $post['Photo']));
     $questions = Questions::where('PostID', '=', $id)->get()->toArray();
     foreach ($questions as $question) {
         QuestionsController::destroy($question['id']);
     }
     $courseid = $post['CourseID'];
     $post->delete();
     $course = Courses::find($post->CourseID);
     $course->NoOfPosts--;
     $course->update();
     return redirect(route('admin.viewcourse', $courseid));
 }
예제 #23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = Posts::find($postid)['FormatID'];
     if ($format == 1) {
         $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
         foreach ($answers as $answer) {
             Answers::destroy($answer['id']);
         }
     } else {
         if ($format == 2) {
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
         }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }
 public function getAnswerDetail()
 {
     $request = Request::capture();
     $token = $request->input('token');
     $answerId = $request->input('answerId');
     $userId = AuthController::getUserIdByToken($token);
     if ($userId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败');
     }
     if ($answerId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_Error, '', 'answerId不能为空');
     }
     $answer = Answer::select('id', 'answer_content', 'answer_time', 'question_id', 'user_id', 'is_resolved')->where('id', $answerId)->first()->toArray();
     //        print_r($question);
     // 个人信息
     $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $answer['user_id'])->first()->toArray();
     $answer = array_merge($answer, $userInfo);
     // 图片
     $picIds = AnswerPictures::select('pic_id')->where('answer_id', $answer['id'])->get()->toArray();
     $pics = Picture::whereIn('id', $picIds)->get()->toArray();
     $answer = array_merge($answer, ['image' => $pics]);
     // 评论数
     $comments = Comment::where('answer_id', $answer['id'])->count();
     $answer = array_merge($answer, ['commentNumber' => $comments]);
     // 赞数
     $upCount = AnswerUp::where('answer_id', $answer['id'])->count();
     $answer = array_merge($answer, ['upNumber' => $upCount]);
     return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $answer, '请求成功');
 }
 public function testUserNameIsEmailField()
 {
     $auth_controller = new AuthController();
     $this->assertEquals('email', $auth_controller->loginUsername());
 }