예제 #1
0
        public async Task <IActionResult> Login([FromBody] MobileLoginCommand command)
        {
            command.TokenId = Guid.NewGuid();
            await DispatchAsync(command);

            var token = cache.Get <string>(command.TokenId);

            if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token))
            {
                return(Unauthorized());
            }

            return(Ok(token));
        }
예제 #2
0
        public async Task <IActionResult> LoginMobile([FromBody] MobileLoginCommand command)
        {
            if (Request.Headers["Api-Key"] != settings.ApiKey)
            {
                return(Unauthorized());
            }

            command.TokenId = Guid.NewGuid();
            await DispatchAsync(command);

            var token = cache.Get <string>(command.TokenId);

            if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token))
            {
                return(Unauthorized());
            }

            return(Ok(token));
        }
예제 #3
0
        public async Task ValidateLoginAsync(MobileLoginCommand command)
        {
            var user = await userRepository.GetAsync(command.Username);

            if (user == null)
            {
                return;
            }

            var hash = encrypter.GetHash(command.Password, user.Salt);

            if (hash != user.Password)
            {
                return;
            }

            var token = jwtHandlerService.CreateToken(user.ExternalId);

            cache.Set(command.TokenId, token);
        }