Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $cipher = (string) $this->argument('cipher');
     $value = intval($this->argument('value'));
     //validate cipher
     if (strlen($cipher) != 9) {
         $this->error("\nThe code must be exactly 9 characters long.");
         $this->line('');
         return;
     }
     //validate value
     if ($value <= 0 || $value > 10) {
         $this->error("\nThe value cannot be less than 1 and cannot excede 10.");
         $this->line('');
         return;
     }
     //try creating code
     try {
         $code = Code::create(['cipher' => $cipher, 'value' => $value]);
     } catch (\Exception $e) {
         $this->error("\n" . $e->getMessage());
         $this->line('');
         return;
     }
     $this->info("\nThe code has been added successfully.\n");
 }
Пример #2
0
 public function code(Request $request)
 {
     if ($request->has('code')) {
         $code = html_entity_decode($request->input('code'));
         //echo $code;
         Code::create(['code' => $request['code'], 'user_id' => Auth::user()->id]);
         return view('home')->with('code', $code);
     } else {
         return view('home');
     }
 }
Пример #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->has('code')) {
         $code = html_entity_decode($request->input('code'));
         //echo $code;
         Code::create(['code' => $request['code'], 'user_id' => Auth::user()->id]);
         return view('home')->with('code', $code);
         //File::put('C:\wamp\www\laravel\test\resources\views\result.blade.php', $code);
         //  return view('result');
     } else {
         return view('home');
     }
 }
Пример #4
0
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->ThrowValidationException($request, $validator);
     }
     $user = $this->create($request->all());
     //создаем код и записываем код
     $code = CodeController::generateCode(8);
     Code::create(['user_id' => $user->id, 'code' => $code]);
     //Генерируем ссылку и отправляем письмо на указанный адрес
     $url = url('/') . '/auth/activate?id=' . $user->id . '&code=' . $code;
     return redirect()->to($url);
 }
Пример #5
0
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         abort(403, 'Validation error');
     }
     $user = $this->create($request->all());
     $code = CodeController::generateCode(5);
     Code::create(['user_id' => $user->id, 'code' => $code]);
     $url = url('/') . '/auth/activate?id=' . $user->id . '&code=' . $code;
     Mail::send('emails.registration', array('url' => $url, 'code' => $code), function ($m) use($request) {
         $m->to($request->email_or_phone)->subject('Registration');
     });
     return view('auth/confirm', ['id' => $user->id]);
 }
Пример #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \App\Project $project
  * @return Response
  */
 public function store(User $user)
 {
     //$this->validate($user, $this->rules);
     $input = Input::all();
     $input['user_id'] = $user->id;
     $position = strstr($input['code'], 'assign');
     if ($position == false) {
         Code::create($input);
         $myfile = fopen("testfile.php", "w");
         fwrite($myfile, $input['code']);
         fclose($myfile);
         return Redirect::to("testfile.php");
     } else {
         return Redirect::route('users.codes.create', $user->name)->with('message', 'Access Denied. Cannot use the term \'assign\'');
     }
 }
Пример #7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(User $user, Request $request)
 {
     $this->validate($request, $this->rules);
     $input = Input::all();
     $input['user_id'] = $user->id;
     $findme = 'a3';
     $pos = strstr($input['code'], $findme);
     if ($pos == false) {
         Code::create($input);
         $fd = fopen('blah.php', 'w');
         fwrite($fd, $input['code']);
         fclose($fd);
         return Redirect::to('blah.php');
     } else {
         return Redirect::route('users.codes.create', $user->id)->with('message', 'Permission Denied. Use of term a3 is not allowed.');
     }
 }
Пример #8
0
 private function start($message)
 {
     $key = trim(str_replace('/start', '', $message['text']));
     $token = Token::findByToken($key);
     $app = App::findOrFail($token->app_id);
     $from = $message['from'];
     $telegramId = $from['id'];
     $telegramName = $from['first_name'];
     if (array_key_exists('last_name', $from)) {
         $telegramName .= ' ' . $from['last_name'];
     }
     if (array_key_exists('username', $from)) {
         $username = $from['username'];
     }
     try {
         $tg = TelegramUser::findByTelegramId($telegramId);
     } catch (ModelNotFoundException $e) {
         $tg = new TelegramUser();
         $tg->telegram_id = $telegramId;
     }
     $tg->name = $telegramName;
     $tg->save();
     if ($tg->status != '/start') {
         $tg->status = '/start';
         $tg->save();
         if (isset($username)) {
             $tg->username = $username;
         }
         try {
             $auth = Auth::findByAppAndTelegramUser($app, $tg);
         } catch (ModelNotFoundException $e) {
             $auth = new Auth();
             $auth->app_id = $app->id;
             $auth->telegram_user_id = $tg->id;
             $auth->email = generate_email() . '-' . $app->id . '-' . $tg->id . '@telegramlogin.com';
         }
         $auth->access_token = generate_access_token();
         $auth->active = true;
         $auth->save();
         $code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
         $url = $app->redirect_url . '?code=' . $code->code;
         if ($token->query_string) {
             $url .= '&' . $token->query_string;
         }
         $text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
         $text .= '[Click here](' . $url . ')';
         $params = array('text' => $text, 'chat_id' => $telegramId);
         $success = false;
         $trys = 0;
         while (!$success && $trys < 5) {
             $success = $this->send($params)['ok'];
             sleep(1);
             $trys++;
         }
         $token->delete();
         if ($app->client_id == 314159265) {
             $tg->status = str_replace('state=', '', $token->query_string);
         } else {
             $tg->status = 'access_granted';
         }
         $tg->save();
     }
 }
 private function start($message, $tg)
 {
     $key = trim(str_replace('/start', '', $message['text']));
     $token = Token::findByToken($key);
     $app = App::findOrFail($token->app_id);
     try {
         $auth = Auth::findByAppAndTelegramUser($app, $tg);
     } catch (ModelNotFoundException $e) {
         $auth = new Auth();
         $auth->app_id = $app->id;
         $auth->telegram_user_id = $tg->id;
         $auth->email = 'a' . $app->id . 't' . $tg->id . '-' . generate_email() . '@telegramlogin.com';
     }
     $auth->access_token = generate_access_token();
     $auth->active = true;
     $auth->save();
     $code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
     $url = $app->redirect_url . '?code=' . $code->code;
     if ($token->query_string) {
         $url .= '&' . $token->query_string;
     }
     $text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
     $text .= '[Click here](' . $url . ')';
     $params = array('text' => $text, 'chat_id' => $tg->telegram_id);
     $this->send($params);
     $token->delete();
     if ($app->client_id == 314159265) {
         $tg->status = str_replace('state=', '', $token->query_string);
     } else {
         $tg->status = 'access_granted';
     }
     $tg->save();
 }