public function send(Request $request) { if ($request->session()->has('uid') == false) { return response()->json(['error' => 'Access denied'], 403, ['Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Credentials' => 'true']); } $message = $request->get('message'); $user = User::where('id', $request->session()->get('uid'))->first(); $user->last_seen = Carbon::now()->toDateTimeString(); $user->save(); $message = LinkFinder::replace($message); if (!$user) { exit; } $nickname = $user->nickname; if ($nickname == null) { header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Credentials: true'); die('error'); } if ($nickname != null && $message != null) { $messages = new Messages(); $messages->user_id = $user->id; $messages->message = $message; Cache::put($nickname, $nickname, 10); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Credentials: true'); header('Content-Type: application/json'); echo json_encode(['success' => $messages->save(), 'message' => $messages->message]); exit; } return response()->json(['success' => false])->header('Access-Control-Allow-Origin', '*'); }
public function register(Request $request) { $nickname = $request->get('nickname'); $password = $request->get('password'); $email = $request->get('email'); $validator = Validator::make(['email' => $email], ['email' => 'required|email']); if ($validator->fails()) { return response()->json(['error' => 'Wrong email']); } if (User::where('nickname', '=', $nickname)->orWhere('email', '=', $email)->exists()) { return response()->json(['error' => 'User exists']); } $u = new User(); $u->nickname = $nickname; $u->email = $email; $u->real_pass = $password; $u->password = Hash::make($password); $token = sha1(md5(rand()) . rand() . time()); $u->confirmation_token = $token; $u->save(); Mail::send('emails.confirmation', ['token' => $token], function ($message) use($email) { $message->subject(trans('email.register_confirm') . ' - VG Chat')->to($email); }); return response()->json(['success' => true]); }
public function handle(Request $request, Closure $next) { $access_token = $request->get('access_token'); if ($access_token == null) { return response()->json(['error' => 'No access']); } $user = User::where('access_token', '=', $access_token)->first(); if ($user == null) { return response()->json(['error' => 'No access']); } if ($user->confirmed == 0) { return response()->json(['error' => 'Not confirmed']); } return $next($request); }
public function doResetting(Request $request, $token) { if ($request->session()->get('resetting', false) != true) { return redirect()->to('/'); } else { $password = $request->get('password'); if ($password == null || strlen(trim($password)) < 6) { return redirect()->back()->with('error', trans('register.password_length')); } $user = User::where('id', $request->session()->get('ruid'))->first(); $user->password = Hash::make($password); $user->save(); $r = Resetting::where('token', $token)->first(); if ($r != null) { $r->forceDelete(); } $request->session()->clear(); $request->session()->flush(); return redirect()->to('/')->with('success', trans('resetting.password_set')); } }
/** * @return User | null */ private function getUser() { return User::where('id', $this->uid)->first(); }
public function settingsSave(Request $request) { $user = $this->getUser(); if ($request->has('newPass')) { $old = $request->get('oldPass'); if (Hash::check($old, $user->password) == false) { return redirect()->back()->with('error', trans('settings.wrong_current')); } elseif (strlen($request->get('newPass')) < 6) { return redirect()->back()->with('error', trans('register.password_length')); } else { $user->password = Hash::make($request->get('newPass')); } } if ($request->has('nickname') && ($nickname = $request->get('nickname')) != $user->nickname) { if (User::where('nickname', $nickname)->exists()) { return redirect()->back()->with('error', trans('register.nickname_taken')); } else { $user->nickname = $nickname; } } if ($request->has('email') && $request->get('email') != $user->email) { $email = $request->get('email'); $vld = Validator::make(['email' => $email], ['email' => 'email']); if ($vld->fails()) { return redirect()->back()->with('error', trans('settings.wrong_email')); } else { if (User::where('email', $email)->exists()) { return redirect()->back()->with('error', trans('register.email_registered')); } else { $user->email = $email; } } } if ($request->hasFile('avatar')) { $file = $request->file('avatar'); $nn = md5(rand() . time()) . sha1($user->id . $user->nickname . $user->password) . '.' . $file->getClientOriginalExtension(); $file->move('./u/pics', $nn); $user->avatar = '/u/pics/' . $nn; } $user->save(); return redirect()->back()->with('success', trans('settings.saved')); }