/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $user = new \App\Users();
     $user->id_roles_users = $request->role_id;
     $user->nom = $request->nom;
     $user->prenom = $request->prenom;
     $user->email = $request->mail;
     $user->password = \Hash::make($request->password . \Config::get('constante.salt'));
     $user->statut = $request->statut;
     $user->situation = $request->situation;
     $user->id_villes = $request->ville;
     $user->adresse = $request->adresse;
     $user->telephone = $request->telephone;
     $user->avatar = '/img/users/default.jpg';
     if ($user->save()) {
         return redirect('admin/users');
     } else {
         echo "echec";
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(RegisterRequest $request)
 {
     // Enregistrement d'un Utilisateurs
     $users = new \App\Users();
     // Ajout de l'avatar par default
     $users->avatar = '/img/users/default.jpg';
     $users->nom = $request->nom;
     $users->prenom = $request->prenom;
     $users->email = $request->email;
     $users->id_roles_users = $request->id_roles_users;
     $users->statut = 1;
     if ($request->password == $request->conf_password) {
         $users->password = \Hash::make($request->password . \Config::get('constante.salt'));
     } else {
         return redirect('/')->withFlashMessageError(Lang::get('general.error_password'));
     }
     $users->save();
     // envoie du mail
     Mail::send('mail.register', compact('users'), function ($message) use($users) {
         $message->to($users['email'], '')->subject(Lang::get('general.suscribe_mail_title'));
     });
     return redirect('/')->withFlashMessage(Lang::get('general.success_register'));
 }
Example #3
0
 public function registration()
 {
     $this->_methodName = 'registration';
     $this->resolveParams();
     $arNeed = ['email' => 'required|email|max:200|unique:user', 'firstName' => 'required', 'lastName' => 'required', 'birthday' => 'required|date|date_format:"d.m.Y"'];
     $this->checkAttr($arNeed);
     if (Auth::check() && !Auth::checkAdmin()) {
         throw new \App\Exceptions\ExceptionApiAuthAlready(['email' => $this->_request_params['email'], 'firstName' => $this->_request_params['firstName'], 'lastName' => $this->_request_params['lastName'], 'birthday' => $this->_request_params['birthday']], $this->_typeName, $this->_methodName);
     }
     $reg_user = \App\Users::whereEmail($this->_request_params['email'])->first();
     if (is_null($reg_user)) {
         if (Auth::checkAdmin()) {
             $reg_user = new \App\Users();
             $reg_user->email = $this->_request_params['email'];
             $reg_user->first_name = $this->_request_params['firstName'];
             $reg_user->last_name = $this->_request_params['lastName'];
             $reg_user->bithday = Carbon::createFromFormat('d.m.Y', $this->_request_params['birthday'])->toDateTimeString();
             $password = $this->generateCode(8);
             $this->_user = $reg_user;
             $reg_user->bonusPoint = Auth::user()->point;
             $reg_user->password = Hash::make($password);
             if (isset($this->_request_params['occupation'])) {
                 $arNeed = ['occupation' => 'required|max:64'];
                 $this->checkAttr($arNeed);
                 $reg_user->occupation = $this->_request_params['occupation'];
             }
             if (isset($this->_request_params['city'])) {
                 $arNeed = ['city' => 'required|max:64'];
                 $this->checkAttr($arNeed);
                 $reg_user->city = $this->_request_params['city'];
             }
             if (isset($this->_request_params['street'])) {
                 $arNeed = ['street' => 'required|max:128'];
                 $this->checkAttr($arNeed);
                 $reg_user->street = $this->_request_params['street'];
             }
             $reg_user->save();
             $tasks = \App\Task::where('userAll', 1)->get();
             foreach ($tasks as $task) {
                 $task_user = new \App\UserTask();
                 $task_user->id_task = $task->id;
                 $task_user->id_user = $reg_user->id;
                 $task_user->status = 'available';
                 $task_user->save();
             }
         } else {
             $reg_user = new \App\Users();
             $reg_user->email = $this->_request_params['email'];
             $reg_user->first_name = $this->_request_params['firstName'];
             $reg_user->last_name = $this->_request_params['lastName'];
             $reg_user->bithday = Carbon::createFromFormat('d.m.Y', $this->_request_params['birthday'])->toDateTimeString();
             $password = $this->generateCode(8);
             $reg_user->password = Hash::make($password);
             $this->_user = $reg_user;
             $reg_user->bonusPoint = \App\Admin::all()->first()->point;
             $reg_user->save();
             $tasks = \App\Task::where('userAll', 1)->get();
             foreach ($tasks as $task) {
                 $task_user = new \App\UserTask();
                 $task_user->id_task = $task->id;
                 $task_user->id_user = $reg_user->id;
                 $task_user->status = 'available';
                 $task_user->save();
             }
         }
     } else {
         throw new \App\Exceptions\ExceptionApiUserEmailExist($this->_request_params, $this->_typeName, $this->_methodName);
     }
     Mail::send('mail.welcome', ['data' => ['email' => $reg_user->email, 'password' => $password]], function ($message) {
         $message->to($this->_user->email)->subject('Добро пожаловать!');
     });
     return $this;
 }