Esempio n. 1
0
 /**
  * Handle a login request to the application. Overrided
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, ['login' => 'required', 'password' => 'required']);
     $credentials = $request->only('login', 'password');
     if ($this->auth->attempt($credentials, $request->has('remember'))) {
         if ($this->auth->user()->getStatus() !== 'NEW') {
             Misc::setCredentials($this->auth->user()->getId());
             Misc::setLocale($this->auth->user()->getLanguageId());
             flash()->success("LOGIN_SUCCESS");
             return redirect($this->redirectTo);
         }
         $this->auth->logout();
     }
     return redirect($this->loginPath())->withInput($request->only('login', 'remember'))->withErrors(['login' => "LOGIN_FAILED"]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, AdminUserRequest $request)
 {
     $data = $request->all();
     $user = AdminUserQuery::create()->findPk($id);
     $user->fromArray($data);
     $user->save();
     Misc::setLocale($data['LanguageId']);
     $adminCredentials = AdminCredentialQuery::create()->find();
     $credentials_arr = $request->only('Credentials');
     $credentials_arr = $credentials_arr['Credentials'];
     foreach ($adminCredentials as $adminCredential) {
         $credential_id = $adminCredential->getId();
         $adminUserCredential = AdminUserCredentialQuery::create()->where('admin_user_id = ' . $id)->where('admin_credential_id = ' . $credential_id)->findOne();
         if (isset($credentials_arr[$credential_id])) {
             if (is_null($adminUserCredential)) {
                 $adminUserCredential = new AdminUserCredential();
                 $adminUserCredential->setAdminUserId($id);
                 $adminUserCredential->setAdminCredentialId($credential_id);
             }
             $adminUserCredential->setPermRead(0);
             $adminUserCredential->setPermWrite(0);
             $adminUserCredential->setPermExec(0);
             foreach ($credentials_arr[$credential_id] as $perm) {
                 if ($perm == 'read') {
                     $adminUserCredential->setPermRead(1);
                 } elseif ($perm == 'write') {
                     $adminUserCredential->setPermWrite(1);
                 } elseif ($perm == 'exec') {
                     $adminUserCredential->setPermExec(1);
                 }
             }
             $adminUserCredential->save();
         } else {
             if (!is_null($adminUserCredential)) {
                 $adminUserCredential->delete();
             }
         }
     }
     if ($id == \Auth::user()->getId()) {
         Misc::setCredentials($id);
     }
     flash()->success("UPDATED");
     session(['attribute' => \Lang::get('general.USER')]);
     return redirect($this->main_page);
 }