public async Task <IActionResult> Login([FromBody] LoginDTO credential)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var applicationUsers = _appSettings.ApplicationUsers;

                if (!applicationUsers.Any(u => u.ToUpperInvariant() == credential.Email.ToUpperInvariant()))
                {
                    return(BadRequest());
                }

                var userInfo = await _azureBusiness.Login(credential).ConfigureAwait(false);

                if (userInfo == null)
                {
                    return(Unauthorized());
                }

                var accessToken = _tokenService.RetrieveToken(userInfo);

                return(Ok(accessToken));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> CheckIn([FromBody] CheckInDTO checkInDTO)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var loginDto = _mapper.Map <LoginDTO>(checkInDTO);
                var userInfo = await _azureBusiness.Login(loginDto).ConfigureAwait(false);

                if (userInfo == null)
                {
                    return(Unauthorized());
                }

                var checkInResult = await _trackerBusiness.CheckInAsync(checkInDTO, userInfo).ConfigureAwait(false);

                if (!checkInResult)
                {
                    return(BadRequest(new { Message = "Unable to checkin device." }));
                }

                return(Ok(userInfo));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }