Exemplo n.º 1
1
 public function loginRequest()
 {
     $response['status'] = 'error';
     $response['title'] = trans('users.check_login_details');
     $response['message'] = trans('users.auth_not_successful');
     if (!empty($_POST) && !empty(Input::get('email')) && !empty(Input::get('password'))) {
         $is_admin = Model_Users::getUserGroup(FALSE, Input::get('email'));
         if ($is_admin == 1) {
             //User data and Authentication
             $credentials = ['email' => Input::get('email'), 'password' => Input::get('password')];
             $user = Sentinel::authenticate($credentials);
             //If Authentication was successful
             if (!empty($user)) {
                 //Login and remember
                 if (!empty(Input::get('remember'))) {
                     Sentinel::loginAndRemember($user);
                 } else {
                     //Login without remember
                     Sentinel::login($user);
                 }
                 $response['status'] = 'success';
                 $response['title'] = trans('global.redirecting') . '...';
                 $response['message'] = trans('users.auth_successful');
             }
         } else {
             $response['title'] = trans('user_notifications.access_denied');
             $response['message'] = trans('user_notifications.no_admin_permission');
         }
     }
     echo json_encode($response);
 }
Exemplo n.º 2
0
 public function doRegister()
 {
     if (!empty($request['email'] = Input::get('email')) && !empty($request['password'] = Input::get('password'))) {
         if (!Sentinel::findByCredentials($request)) {
             if (!filter_var($request['email'], FILTER_VALIDATE_EMAIL)) {
                 $response['status'] = 'warning';
                 $response['message'] = trans('user_notifications.invalid_email');
             } else {
                 if (mb_strlen(Input::get('password')) < 8) {
                     $response['status'] = 'warning';
                     $response['message'] = trans('user_notifications.password_length');
                 } else {
                     if (Sentinel::registerAndActivate($request)) {
                         $user = Sentinel::authenticate($request);
                         //If Authentication was successful
                         if (!empty($user)) {
                             Sentinel::loginAndRemember($user);
                         }
                         $data = ['sys_title' => $this->system['title'], 'sys_email' => $this->system['email'], 'user' => $user];
                         Mail::send('dressplace::emails.register', $data, function ($m) use($data) {
                             $m->from($data['sys_email'], $data['sys_title']);
                             $m->replyTo($data['sys_email'], $data['sys_title']);
                             $m->to($data['user']['email'], $data['user']['email'])->subject(trans('client.register_mail'));
                         });
                         $response['status'] = 'success';
                         $response['message'] = trans('user_notifications.user_created');
                     } else {
                         $response['status'] = 'error';
                         $response['message'] = trans('user_notifications.user_not_created');
                     }
                 }
             }
         } else {
             $response['status'] = 'error';
             $response['message'] = trans('user_notifications.user_exists');
         }
     } else {
         $response['status'] = 'warning';
         $response['message'] = trans('global.all_fields_required');
     }
     echo json_encode($response);
 }