Ejemplo n.º 1
0
 /**
  * Show the application dashboard to the user.
  * 
  * @return Response
  */
 public function index($category_id = 0)
 {
     $keyword = trim(Input::get('keyword'));
     $data['keyword'] = $keyword;
     if (Auth::check() && Auth::user()->hasRole('user')) {
         $category_id = trim($category_id);
         $url_image = LibraryPublic::get_url_image(Auth::user()->image);
         Session::put('url_image_auth', $url_image);
         $rules = ['keyword' => 'max:150|min:1'];
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             $data['keyword'] = "";
             $posts = Post::get_all_posts($category_id);
         } else {
             $posts = Post::get_all_posts($category_id, $keyword);
         }
         $data['posts'] = $posts;
         $data['categories'] = Category::all();
     }
     if (Auth::check() && Auth::user()->hasRole('admin')) {
         return redirect('admin');
     }
     return view('home', $data);
 }
Ejemplo n.º 2
0
 /**
  * Function setting account of user
  * @method POST
  * @author Tran Van Moi
  * @since  2015/05/20
  * @return response
  */
 public function postSetting()
 {
     $data = Input::all();
     $validator = User::validate($data, 'edit');
     if ($validator->fails()) {
         return redirect('user/setting')->withInput()->withErrors($validator);
     } else {
         if (Hash::check($data['current_password'], Auth::user()->password)) {
             $user = Auth::user();
             $user->name = $data['name'];
             $user->address = $data['address'];
             $user->birthday = $data['birthday'];
             if (Input::file('image')) {
                 $destination_path = './public/images/avatar/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $file_name = str_random(8) . '.' . $extension;
                 // renameing image
                 if (Input::file('image')->move($destination_path, $file_name)) {
                     if ($user->image != "default.jpg" && File::exists($destination_path . $user->image)) {
                         File::delete($destination_path . $user->image);
                     }
                     $user->image = $file_name;
                 }
             }
             if ($data['password'] != "" && $data['password'] == $data['password_confirmation']) {
                 $user->password = Hash::make($data['password']);
             }
             $user->save();
             $url_image = LibraryPublic::get_url_image($user->image);
             Session::put('url_image_auth', $url_image);
             return redirect('user/setting')->withInput()->with('setting_status', ['status' => 'success', 'message' => 'Setting account is success!']);
         } else {
             return redirect('user/setting')->withInput()->with('setting_status', ['status' => 'danger', 'message' => 'Password is not correct']);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Admin edit user
  * @author  Tran Van Moi
  * @since  2015/06/01
  * @param  int $id
  * @return Response
  */
 public function postEdit($id = null)
 {
     $id = trim($id);
     $user = User::find($id);
     if ($user) {
         $data = Input::all();
         $data['id'] = $id;
         $validator = User::validate($data, 'admin-edit');
         if ($validator->fails()) {
             return Redirect::to('admin/user/edit/' . $id)->withInput()->withErrors($validator);
         } else {
             $user->name = $data['name'];
             $user->email = $data['email'];
             $user->birthday = $data['birthday'];
             $user->address = $data['address'];
             if (Input::file('image')) {
                 $destination_path = './public/images/avatar/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $file_name = str_random(8) . '.' . $extension;
                 // renameing image
                 if (Input::file('image')->move($destination_path, $file_name)) {
                     if ($user->image != "default.jpg" && File::exists($destination_path . $user->image)) {
                         File::delete($destination_path . $user->image);
                     }
                     $user->image = $file_name;
                 }
             }
             if ($data['password'] != "") {
                 $user->password = Hash::make($data['password']);
             }
             $user->save();
             $url_image = LibraryPublic::get_url_image($user->image);
             Session::put('url_image_edit_user', $url_image);
             return redirect('admin/user/edit/' . $id)->withInput()->with('edit_status', ['status' => 'success', 'message' => 'Setting account is success!']);
         }
     } else {
         return redirect('admin/user/edit');
     }
 }