/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $conversation = Conversation::create(['subject' => $input['subject']]); $message = Message::create(['conversation_id' => $conversation->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); $sender = Participant::create(['conversation_id' => $conversation->id, 'user_id' => Auth::user()->id]); if ($this->input->has('recipient')) { $recipient = User::where('email', $input['recipient'])->first(); Participant::create(['conversation_id' => $conversation->id, 'user_id' => $recipient->id]); } return Redirect::route('conversations.index'); }
public function showProfile($user) { $u = User::where('pseudo', '=', $user)->first(); if (is_null($u)) { App::abort(404); } if (Auth::user() == $u) { $editable = true; } else { $editable = false; } $expData = ExperienceManager::getExpInfo($u); return view('user.showProfile', ['user' => $u, 'streamer' => $u->isStreamer(), 'editable' => $editable, 'level' => $expData['level'], 'progression' => $expData['progression']]); }
public static function login($username, $password) { $error = ['user' => FALSE, 'password' => FALSE]; $logged = FALSE; $cookie = ['username' => '', 'email' => '']; try { $user = User::where('username', $username)->firstOrFail(); } catch (Exception $e) { $error["user"] = TRUE; echo "username not found"; return $error; } $password = hash('sha256', $password . $user->salt); if ($password == $user->password) { $logged = TRUE; $cookie['username'] = $username; $cookie['email'] = $user->email; $_SESSION['user'] = $cookie; } else { $error['password'] = TRUE; echo "password doesn't match"; return $error; } }
public function checkLogin() { if (empty($_SESSION)) { session_start(); } empty($_SESSION['old']) ?: ($_SESSION['old'] = []); empty($_SESSION['error']) ?: ($_SESSION['error'] = []); $rules = ['email' => FILTER_VALIDATE_EMAIL, 'password' => FILTER_SANITIZE_STRING]; $sanitize = filter_input_array(INPUT_POST, $rules); $error = false; if (!$sanitize['email']) { $_SESSION['error']['email'] = 'your email is invalid'; $error = true; } if (!$sanitize['password']) { $_SESSION['error']['password'] = '******'; $error = true; } if ($error) { $_SESSION['flashMessage'] = 'there was a problem'; $this->redirect(url('login')); } $user = new User(); if ($u = $user->where('email', '=', $sanitize['email'])->get()->fetch()) { if (password_verify($sanitize['password'], $u->password)) { session_regenerate_id(true); $_SESSION['secu'] = $sanitize['email']; $this->redirect(url('dashboard')); } } }
/** * Gets a user by the given E-Mail address * * @param String $email * @return Users the user with the given email */ public static function getUserByEmail($email) { return User::where("email", "=", $email)->first(); }