/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store()
 {
     $data = Request::all();
     $user = new \App\User();
     $user->fill($data);
     $user->save();
     return response()->json(["id" => $user->id]);
 }
 public function signup()
 {
     if (Auth::check()) {
         return redirect()->intended('dashboard');
     }
     $user = new \App\User();
     $name = Input::get('email');
     $password = "******";
     if ($name) {
         $email = Input::get('email');
         $username = Input::get('username');
         $validators = Validator::make(['email' => $email, 'username' => $username], ['email' => 'required|email|unique:sendersysusers', 'username' => 'required'], ['required' => 'Вы не заполнили поле :attribute', 'email' => 'Email быть корректным', 'unique' => 'Такой :attribute уже используется', 'min' => 'Поле :attribute должно содержать минимум :min символов']);
         if ($validators->fails()) {
             $errorMessage = $validators->messages();
             $errors = "";
             foreach ($errorMessage->all() as $messages) {
                 $errors .= $messages . " ";
                 // dd($errors);
             }
         } else {
             $user->fill(Input::all());
             $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             $charactersLength = strlen($characters);
             $randomString = '';
             for ($i = 0; $i < 10; $i++) {
                 $randomString .= $characters[rand(0, $charactersLength - 1)];
             }
             $user->{$password} = $randomString;
             if ($user->signup()) {
                 $success = "Пользователь успешно зарегистрирован";
                 $emailSend = Input::get('email');
                 $to = '<' . $email . '>';
                 $subject = "Добро пожаловать на Sendersys;";
                 $message = ' <h3>Ваш пароль</h3>' . $randomString . ' </br>';
                 $mailheaders = "Content-type: text/html; UTF-8 \r\n";
                 $mailheaders .= "From: no-reply@sendersys.ru";
                 mail($to, $subject, $message, $mailheaders);
                 return view('main', array('emailSend' => isset($emailSend) ? $emailSend : null));
             }
         }
     }
     return view('main')->with('signup_errors', array(isset($errors) ? $errors : null));
 }