コード例 #1
0
 public function postVote()
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $rules = array('MCUsername' => 'required|max:40', 'g-recaptcha-response' => 'required|recaptcha', 'sid' => 'required');
     $v = Validator::make($input, $rules);
     $sid = $input['sid'];
     $server = DB::table('mcservers')->where('mcs_id', '=', $sid)->first();
     if (!count($server)) {
         return Redirect::to('/minecraft/' . $sid)->withErrors("Ocorreu um erro com a validação do servidor");
     }
     if ($v->passes()) {
         if (mcservers::playerHasVoted($sid, $input['MCUsername']) || mcservers::ipHasVoted($sid, $_SERVER["HTTP_CF_CONNECTING_IP"])) {
             return Redirect::to('/minecraft/' . $sid)->withErrors("Já votaste hoje");
         }
         if ($server->mcs_votifier == 1) {
             $votifier = Votifier::newVote($server->mcs_ip, $server->mcs_vport, $server->mcs_votifierkey, $input['MCUsername']);
             if ($votifier == false) {
                 return Redirect::to('/minecraft/' . $sid)->withErrors("Não foi possivel enviar o voto para o servidor, porfavor contacta o admininstrador do mesmo");
             }
         }
         if (Auth::check()) {
             DB::table('users')->where('id', Auth::user()->id)->update(array('votes' => Auth::user()->votes + 1));
             utilities::log("Voted On Server " . $server->mcs_name);
         }
         DB::table('mcservers')->where('mcs_id', $sid)->update(array('mcs_tvotes' => $server->mcs_tvotes + 1, 'mcs_mvotes' => $server->mcs_mvotes + 1));
         DB::table('mcserversvotes')->insert(array('mcsv_sid' => $sid, 'mcsv_player' => $input['MCUsername'], 'mcsv_ip' => $_SERVER["HTTP_CF_CONNECTING_IP"], 'mcsv_day' => date("j"), 'mcsv_month' => date("n"), 'mcsv_year' => date("Y")));
         return Redirect::to('/minecraft/' . $sid)->With('success', 'Voto Registado!');
     } else {
         return Redirect::to('/minecraft/' . $sid)->withErrors($v);
     }
 }
コード例 #2
0
 public function postRegister()
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $rules = array('regName' => 'required|max:40', 'regEmail' => 'required|email|max:40', 'regPassword' => 'required|min:6|max:20');
     $v = Validator::make($input, $rules);
     if ($v->passes()) {
         if (count(DB::table('users')->where('email', '=', $input['regEmail'])->first())) {
             return Redirect::to(URL::to("/login"))->withInput()->WithErrors("Este Email já está em uso");
         }
         $password = $input['regPassword'];
         $password = Hash::make($password);
         $code = str_random(15);
         $data = array('email' => $input['regEmail'], 'name' => $input['regName']);
         Mail::send('emails.welcome', array('username' => $data['name'], 'code' => $code, 'email' => $data['email']), function ($message) use($data) {
             $message->to($data['email'])->subject('Bem vindo!');
         });
         $user = new User();
         $user->email = $input['regEmail'];
         $user->name = $input['regName'];
         $user->password = $password;
         $user->activation_token = $code;
         $user->save();
         $id = DB::table('users')->where('email', '=', $input['regEmail'])->first();
         utilities::log("Login", $id->id);
         return Redirect::to(URL::to("/login"))->With('success', 'Conta criada, Verifica a tua conta com o link que te foi enviado por Email.');
     } else {
         return Redirect::to(URL::to("/login"))->withInput()->WithErrors($v);
     }
 }
コード例 #3
0
 public function postChangePW()
 {
     $input = Input::all();
     $rules = array('oldpassword' => 'required|min:6|max:20', 'newpassword' => 'required|min:6|max:20', 'g-recaptcha-response' => 'required|recaptcha');
     $v = Validator::make($input, $rules);
     if ($v->passes()) {
         $oldpassword = $input['oldpassword'];
         $oldpasswordsql = Auth::user()->password;
         if ($oldpassword && !Hash::check($oldpassword, $oldpasswordsql)) {
             return Redirect::to('user')->WithErrors('Password Antiga Errada');
         } else {
             $newpassword = $input['newpassword'];
             $newpassword = Hash::make($newpassword);
             DB::table('users')->where('id', '=', Auth::user()->id)->update(array('password' => $newpassword));
             utilities::log("Password Changed");
             return Redirect::to(URL::to("/user"))->With('success', 'Password Atualizada');
         }
     } else {
         return Redirect::to(URL::to("/user"))->WithErrors($v);
     }
 }