コード例 #1
0
        public async Task <IActionResult> CheckIfUserUpdateInfo()
        {
            var userId = GetUserId();

            try
            {
                await _userInformationService.CheckInitializedInfo(userId);
            }
            catch (ObjectNotFoundException e)
            {
                await _userInformationService.AddWithEmptyInfo(userId, "");

                await _unitOfWork.Commit();
            }
            var completedInfoPercentage = await _userInformationService.GetPercentageOfCompletedInfo(userId);

            var isHavingLevel = await _userInformationService.CheckIfUserHaveSpecification(m => m.UserId == userId && m.Level != null);

            return(Ok(new { completedInfoPercentage, isHavingLevel }));
        }
コード例 #2
0
        public async Task <IActionResult> Login(LoginInfoDto loginInfoDto)
        {
            var user = await _userManager.FindByNameAsync(loginInfoDto.UserName);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect!" }));
            }
            var check = await _userInformationService.CheckInitializedInfo(user.Id);

            if (!check)
            {
                await _userInformationService.AddWithEmptyInfo(user.Id, "");

                await _unitOfWork.Commit();
            }
            var userInfo = await _userInformationService.GetOne(user.Id);

            var result = await _authService.AuthenticateUser(user, loginInfoDto.Password, userInfo.IsBlocked);

            switch (result)
            {
            case AuthenticateUserResult.Invalid:
                return(BadRequest(new { message = "Username or password is incorrect!" }));

            case AuthenticateUserResult.Blocked:
                return(Forbid());

            case AuthenticateUserResult.Succeeded:
                var token = await _tokenService.GenerateToken(user, _appSetting.JwtSecret);

                return(Ok(new { token, user.Id }));

            default:
                return(NotFound());
            }
        }