Пример #1
0
        public SignUpInResult SignIn(SignInRequest request)
        {
            return(BaseInvokeCheckModel(request, () =>
            {
                User dataUser = _dbContext.Users
                                .Include(x => x.AuthToken)
                                .FirstOrDefault(x => x.Email == request.Email);

                if (dataUser == null ||
                    !_crypto.IsValid(dataUser.PasswordHash, dataUser.PasswordSalt, request.Password))
                {
                    return ResponseBuilder <SignUpInResult> .Fail().SetInfoAndBuild("Email or password is incorrect");
                }

                UpdateAuthToken(dataUser.AuthToken);

                _dbContext.SaveChanges();

                return ResponseBuilder <SignUpInResult> .SuccessBuild(new SignUpInResult
                {
                    User = UserMapper.ToApi.FromData(dataUser),
                    AuthToken = AuthTokenMapper.ToApi.FromData(dataUser.AuthToken)
                });
            }));
        }