コード例 #1
0
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public LoginResponseModel Login(LoginRequestModel requestModel)
        {
            if (AllowApi)
                if (!CheckApi(new Guid(requestModel.ApiKey)))
                    return new LoginResponseModel()
                    {
                        Code = "-2",
                        Message = "Not allow this function for this API key. Please check again"
                    };

            var userByUserName = string.IsNullOrEmpty(requestModel.MemberEmail) ||
                                 !requestModel.MemberEmail.Contains("@")
                                     ? DataContext.AdministatorUsers.SingleOrDefault(
                                         m => m.AdminUserName.ToLower() == requestModel.MemberUserName.ToLower())
                                     : DataContext.AdministatorUsers.SingleOrDefault(
                                         m => m.AdminEmail.ToLower() == requestModel.MemberEmail.ToLower());

            if (userByUserName == null)
                return new LoginResponseModel
                {
                    Code = "-1",
                    Message = "User name or email is not correct"
                }; // User name is not correct

            requestModel.Password =
                CommonLib.CreateShaHash(new[] { requestModel.Password, userByUserName.AdminId.ToString() });

            //Check password
            if (userByUserName.AdminPassword == requestModel.Password)
            {
                userByUserName.AdminLastLogin = DateTime.UtcNow;
                DataContext.SaveChanges();

                return new LoginResponseModel
                {
                    Code = "1",
                    MemberUserName = userByUserName.AdminUserName,
                    MemberId = userByUserName.AdminId.ToString(),
                    MemberGender = userByUserName.AdminGender,
                    MemberEmail = userByUserName.AdminEmail,
                };
            }
            return new LoginResponseModel
            {
                Code = "-1",
                Message = "Password not match"
            };
        }
コード例 #2
0
ファイル: MemberRepository.cs プロジェクト: nhanthieugia/BSG
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public LoginResponseModel Login(LoginRequestModel requestModel)
        {
            if (AllowApi)
                if (!CheckApi(new Guid(requestModel.ApiKey)))
                    return new LoginResponseModel()
                        {
                            Code = "-2",
                            Message = "Not allow this function for this API key. Please check again"
                        };

            var userByUserName = string.IsNullOrEmpty(requestModel.MemberEmail) ||
                                 !requestModel.MemberEmail.Contains("@")
                                     ? DataContext.MemberUsers.SingleOrDefault(
                                         m => m.MemberUserName.ToLower() == requestModel.MemberUserName.ToLower())
                                     : DataContext.MemberUsers.SingleOrDefault(
                                         m => m.MemberEmail.ToLower() == requestModel.MemberEmail.ToLower());

            if (userByUserName == null)
                return new LoginResponseModel
                    {
                        Code = "-1",
                        Message = "Username or email is not correct"
                    }; // User name is not correct

            if (userByUserName.MemberLocked != 1)
                return new LoginResponseModel
                {
                    Code = "-1",
                    Message = "Account is locked. Please contact admin to unlock!"
                }; // User name is not correct

            requestModel.Password =
                CommonLib.CreateShaHash(new[] {requestModel.Password, userByUserName.MemberId.ToString()});

            //Check password
            if (userByUserName.MemberPassword == requestModel.Password)
            {
                userByUserName.MemberLastLogin = DateTime.UtcNow;
                DataContext.SaveChanges();

                return new LoginResponseModel
                    {
                        Code = "1",
                        MemberCountry = userByUserName.MemberCountry,
                        MemberUserName = userByUserName.MemberUserName,
                        MemberLastName = userByUserName.MemberLastName,
                        MemberId = userByUserName.MemberId.ToString(),
                        MemberGender = userByUserName.MemberGender,
                        MemberFirstName = userByUserName.MemberFirstName,
                        MemberEmail = userByUserName.MemberEmail,
                        FacebookId = userByUserName.MemberFacebookId,
                        Avatar = userByUserName.MemberAvatar,
                        AvatarMedium = userByUserName.MemberAvatarMedium
                    };
            }
            return new LoginResponseModel
                {
                    Code = "-1",
                    Message = "Password not match"
                };
        }