1: <?php
2:
3: 4: 5: 6: 7: 8:
9: class AuthController extends BaseController {
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: public function postLogin() {
28: try {
29:
30: $validator = Validator::make(Input::all(), User::rulesLogin());
31: $username = Input::get('username');
32: $password = md5(Input::get('password'));
33:
34: if ($validator->fails()) {
35: return ws_response(true, Input::except('password'), $validator->errors()->getMessages(), 200);
36: }
37:
38: $user = User::where('username_usr', '=', $username)
39: ->where('password_usr', '=', $password)
40: ->first();
41:
42: if (!empty($user)) {
43:
44:
45: $profile = Profile::join('user_profile', function($join) use ($user) {
46: $join->on('profile.serial_prf', '=', 'user_profile.serial_prf')
47: ->where('user_profile.serial_usr', '=', $user->serial_usr)
48: ->where('user_profile.status_upr', '=', 'ACTIVE');
49: })
50: ->whereIn('profile.name_prf', User::$allowedProfiles)
51: ->where('profile.status_prf', '=', 'ACTIVE')
52: ->select('profile.serial_prf', 'profile.name_prf')
53: ->first();
54: if (!empty($profile)) {
55: $token = JWTAuth::fromUser($user);
56: return ws_response(false, array('token' => $token), 'Acceso Concedido', 200);
57: } else {
58: return ws_response(true, null, 'El usuario no posee un perfil autorizado para acceder', 200);
59: }
60: } else {
61: return ws_response(true, null, 'El usuario y/o la contraseña ingresadas no son credenciales válidas.', 200);
62: }
63: } catch (Exception $ex) {
64: return ws_response(true, null, 'ERROR ' . $ex->getCode() . '! ' . $ex->getMessage(), 500);
65: }
66: }
67:
68: }
69: