Пример #1
0
        /// <summary>
        /// This method is use for login user
        /// </summary>
        /// <param name="loginDTO">Login DTOs pass</param>
        /// <returns></returns>
        public async Task <BaseResponse> ValidateUserAsync(LoginDTO loginDTO)
        {
            try
            {
                string       ConnectionString = _config[_iStringConstants.MyConnectionString];
                BaseResponse baseResponse     = new BaseResponse();
                UserTokenDTO userTokenAC      = new UserTokenDTO();
                using (DeepakdbContext deepakDBContext = new DeepakdbContext())
                {
                    /*var parameterOut=new SqlParameter
                     * {
                     *  ParameterName=
                     * }*/
                    var data = await deepakDBContext.UserDetail.FromSqlRaw("spGetUserDetailByEmail @Email=@p0", parameters : new[] { loginDTO.Email }).ToListAsync();

                    if (data != null)
                    {
                        data.ForEach(x => new UserTokenDTO()
                        {
                            Id           = x.Id,
                            FirstName    = x.FirstName,
                            LastName     = x.LastName,
                            ZipCode      = x.ZipCode,
                            Email        = x.Email,
                            MobileNumber = x.MobileNumber,
                            Password     = x.Password
                        });
                        if (PasswordHashUtill.VerifyHashedPassword(userTokenAC.Password, loginDTO.Password))
                        {
                            baseResponse.StatusCode = (int)EnumList.ResponseType.Success;
                            baseResponse.Data       = userTokenAC;
                        }
                        else
                        {
                            baseResponse.Message    = _iStringConstants.InvalidPassword;
                            baseResponse.StatusCode = (int)EnumList.ResponseType.Error;
                            baseResponse.Data       = null;
                        }
                    }
                    else
                    {
                        baseResponse.Message    = _iStringConstants.LoginCredentailWrong;
                        baseResponse.StatusCode = (int)EnumList.ResponseType.Error;
                        baseResponse.Data       = null;
                    }

                    return(baseResponse);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public async Task <BaseResponseModel> ValidateUserAsync(LoginAC loginAC)
        {
            BaseResponseModel baseResponseModel = new BaseResponseModel();
            UserTokenAC       userTokenAC       = new UserTokenAC();

            using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                try
                {
                    var existingUserQuery = "select * from AspNetUsers where Email='" + loginAC.Email + "'";
                    var userData          = connection.Query(existingUserQuery).FirstOrDefault();
                    if (userData != null)
                    {
                        if (PasswordHashUtill.VerifyHashedPassword(userData.PasswordHash, loginAC.Password))
                        {
                            userTokenAC.Id       = userData.Id;
                            userTokenAC.FullName = userData.UserName;
                            userTokenAC.Email    = userData.Email;

                            baseResponseModel.StatusCode = (int)EnumList.ResponseType.Success;
                            baseResponseModel.Data       = userTokenAC;
                        }
                        else
                        {
                            baseResponseModel.Message    = StringConstant.InvalidPassword;
                            baseResponseModel.StatusCode = (int)EnumList.ResponseType.Error;
                            baseResponseModel.Data       = null;
                        }
                    }
                    else
                    {
                        baseResponseModel.Message    = StringConstant.LoginCredentailWrong;
                        baseResponseModel.StatusCode = (int)EnumList.ResponseType.Error;
                        baseResponseModel.Data       = null;
                    }
                    return(baseResponseModel);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }