diff --git a/customer/app/src/app/services/endpoints.ts b/customer/app/src/app/services/endpoints.ts index 07cfd8d..3fc936f 100644 --- a/customer/app/src/app/services/endpoints.ts +++ b/customer/app/src/app/services/endpoints.ts @@ -6,7 +6,7 @@ export class Endpoints { private static apiUrl: string = environment.apiUrl; public static POST_USERS_AUTHENTICATE(){ - return `${this.apiUrl}user/login`; + return `${this.apiUrl}login/login`; } public static POST_USER_PASSWORD_CHANGE(){ diff --git a/customerapi/controllers/LoginController.php b/customerapi/controllers/LoginController.php new file mode 100644 index 0000000..71502d4 --- /dev/null +++ b/customerapi/controllers/LoginController.php @@ -0,0 +1,60 @@ +load(\Yii::$app->request->post(), ''); + + if ($form->validate()) { + + /** @var Jwt $jwt */ + $jwt = Yii::$app->jwt; + $signer = $jwt->getSigner('HS256'); + $key = $jwt->getKey(); + $time = time(); + + // Adoption for lcobucci/jwt ^4.0 version + $token = $jwt->getBuilder() + ->issuedBy('customerapi')// Configures the issuer (iss claim) + ->permittedFor('customer')// Configures the audience (aud claim) + ->identifiedBy('A989C57D19E2AF756BA9585AC4CFAF7974AE3D2BCA7CCA7307B39AB28CC7C2C8', true)// Configures the id (jti claim), replicating as a header item + ->issuedAt($time)// Configures the time that the token was issue (iat claim) + ->expiresAt($time + 3600)// Configures the expiration time of the token (exp claim) + ->withClaim('uid', $form->getCustomer()->getId())// Configures a new claim, called "uid" + ->getToken($signer, $key); // Retrieves the generated token + + return $this->asJson([ + 'token' => (string)$token, + ]); + } else { + throw new UnauthorizedHttpException("Hibás e-mail cím vagy jelszó!"); + } + } + +} diff --git a/customerapi/controllers/UserController.php b/customerapi/controllers/UserController.php index 1c69851..9ee4b6f 100644 --- a/customerapi/controllers/UserController.php +++ b/customerapi/controllers/UserController.php @@ -9,61 +9,14 @@ namespace customerapi\controllers; use common\models\Customer; -use customerapi\models\LoginForm; use customerapi\models\PasswordChangeForm; -use sizeg\jwt\Jwt; -use Yii; use yii\web\BadRequestHttpException; -use yii\web\UnauthorizedHttpException; /** @noinspection PhpUnused */ class UserController extends RestController { - - /** - * hash for password test is: - * $2y$13$D2BauYE2nhCdVDNatT9BMeWGxOvi5t5V6W2OUjr6sj2FRpb317Cpq - * - */ - /** @noinspection PhpUnused */ - public function actionLogin() - { -// $customer = new Customer(); -// $customer->setPassword("test"); - $form = new LoginForm(); - - $form->load(\Yii::$app->request->post(), ''); - - if ($form->validate()) { - - - /** @var Jwt $jwt */ - $jwt = Yii::$app->jwt; - $signer = $jwt->getSigner('HS256'); - $key = $jwt->getKey(); - $time = time(); - - // Adoption for lcobucci/jwt ^4.0 version - $token = $jwt->getBuilder() - ->issuedBy('customerapi')// Configures the issuer (iss claim) - ->permittedFor('customer')// Configures the audience (aud claim) - ->identifiedBy('A989C57D19E2AF756BA9585AC4CFAF7974AE3D2BCA7CCA7307B39AB28CC7C2C8', true)// Configures the id (jti claim), replicating as a header item - ->issuedAt($time)// Configures the time that the token was issue (iat claim) - ->expiresAt($time + 3600)// Configures the expiration time of the token (exp claim) - ->withClaim('uid', $form->getCustomer()->getId())// Configures a new claim, called "uid" - ->getToken($signer, $key); // Retrieves the generated token - - return $this->asJson([ - 'token' => (string)$token, - ]); - } else { - throw new UnauthorizedHttpException("Hibás e-mail cím vagy jelszó!"); - } - - } - /** * @throws \yii\base\InvalidConfigException * @throws \yii\base\Exception @@ -91,10 +44,4 @@ class UserController extends RestController $customer->save(); } - protected function getOptionalActions() - { - return ['login']; - } - - }