Пример #1
0
        public Result<ServiceResponse> Login(LoginRequest request)
        {
            return this.ExecuteMethod(() =>
            {
                request.CheckNotNull();

                if (string.IsNullOrEmpty(request.Username))
                    throw new ArgumentNullException("username");

                var username = request.Username;
                
                if (WebSecurityHelper.Authenticate(ref username, request.Password, false))
                    return new ServiceResponse();

                throw new ValidationError("AuthenticationError", Texts.Validation.AuthenticationError);
            });
        }
Пример #2
0
        public Result<ServiceResponse> Login(LoginRequest request)
        {
            return this.ExecuteMethod(() =>
            {
                request.CheckNotNull();

                if (request.Username == null)
                    throw new ArgumentNullException("username");

                var username = request.Username;

                if (WebSecurityHelper.Authenticate(ref username, request.Password, false))
                    return new ServiceResponse();

                throw new ValidationError("AuthenticationError", null, "Invalid username or password!");
            });
        }
Пример #3
0
        public Result <ServiceResponse> Login(LoginRequest request)
        {
            return(this.ExecuteMethod(() =>
            {
                request.CheckNotNull();

                if (string.IsNullOrEmpty(request.Username))
                {
                    throw new ArgumentNullException("username");
                }

                var username = request.Username;

                if (WebSecurityHelper.Authenticate(ref username, request.Password, false))
                {
                    return new ServiceResponse();
                }

                throw new ValidationError("AuthenticationError", Texts.Validation.AuthenticationError);
            }));
        }
Пример #4
0
        public Result <ServiceResponse> Login(LoginRequest request)
        {
            return(this.ExecuteMethod(() =>
            {
                request.CheckNotNull();

                if (string.IsNullOrEmpty(request.Username))
                {
                    throw new ArgumentNullException("username");
                }

                var username = request.Username;

                if (Dependency.Resolve <IAuthenticationService>().Validate(ref username, request.Password))
                {
                    CheckTwoFactorAuthentication(username, request);

                    WebSecurityHelper.SetAuthenticationTicket(username, false);
                    return new ServiceResponse();
                }

                throw new ValidationError("AuthenticationError", Texts.Validation.AuthenticationError);
            }));
        }
Пример #5
0
        public BaseApiResponse ShopLogin(LoginRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (!request.Mobile.IsMobileNumber())
            {//是否手机号
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号格式不正确"
                });
            }
            var userinfo = _userQueryService.FindUser(request.Mobile);

            //验证用户
            if (userinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该账号"
                });
            }
            //验证密码
            if (!PasswordHash.ValidatePassword(request.Password, userinfo.Password))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "登录密码错误"
                });
            }


            //店铺信息
            var storeinfo = _storeQueryService.InfoByUserId(userinfo.Id);

            if (storeinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "您没有店铺"
                });
            }
            _apiSession.SetAuthCookie(HttpContext.Current.Response, userinfo.Id.ToString());
            _apiSession.SetUserInfo(userinfo.Id.ToString(), userinfo.ToUserModel());
            return(new ShopLoginResponse
            {
                UserInfo = new UserInfo
                {
                    Id = userinfo.Id,
                    NickName = userinfo.NickName,
                    Portrait = userinfo.Portrait.ToOssStyleUrl(OssImageStyles.UserPortrait.ToDescription()),
                    Mobile = userinfo.Mobile,
                    Gender = userinfo.Gender,
                    Region = userinfo.Region,
                    Role = userinfo.Role.ToDescription(),
                    StoreId = storeinfo.Id.ToString(),
                    CartId = userinfo.CartId.ToString(),
                    Token = userinfo.Id.ToString()
                },
                StoreInfo = new StoreInfo
                {
                    Id = storeinfo.Id,
                    Name = storeinfo.Name,
                    Description = storeinfo.Description,
                    Region = storeinfo.Region,
                    Address = storeinfo.Address,
                    TodayOrder = storeinfo.TodayOrder,
                    TodaySale = storeinfo.TodaySale,
                    TotalOrder = storeinfo.TotalOrder,
                    TotalSale = storeinfo.TotalSale
                }
            });
        }
Пример #6
0
        public BaseApiResponse Login(LoginRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (!request.Mobile.IsMobileNumber())
            {//是否手机号
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号格式不正确"
                });
            }
            var userinfo = _userQueryService.FindUser(request.Mobile);

            //验证用户
            if (userinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该账号"
                });
            }
            //验证密码
            if (!PasswordHash.ValidatePassword(request.Password, userinfo.Password))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "登录密码错误"
                });
            }
            //设置cookie 和缓存
            _apiSession.SetAuthCookie(HttpContext.Current.Response, userinfo.Id.ToString());
            _apiSession.SetUserInfo(userinfo.Id.ToString(), userinfo.ToUserModel());

            //获取钱包信息
            var walletinfo = _walletQueryService.Info(userinfo.WalletId);

            if (walletinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "获取钱包信息失败"
                });
            }
            _apiSession.SetWalletInfo(walletinfo.Id.ToString(), walletinfo.ToWalletModel());
            //购物车信息
            var cart = _cartQueryService.Info(userinfo.CartId);

            if (cart == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "获取购物车信息失败"
                });
            }
            //店铺信息
            var storeId   = "";
            var storeinfo = _storeQueryService.InfoByUserId(userinfo.Id);

            if (storeinfo != null)
            {
                storeId = storeinfo.Id.ToString();
            }

            return(new LoginResponse
            {
                UserInfo = new UserInfo
                {
                    Id = userinfo.Id,
                    ParentId = userinfo.ParentId,
                    NickName = userinfo.NickName,
                    Portrait = userinfo.Portrait.ToOssStyleUrl(OssImageStyles.UserPortrait.ToDescription()),
                    Mobile = userinfo.Mobile,
                    Gender = userinfo.Gender,
                    Region = userinfo.Region,
                    Role = userinfo.Role.ToDescription(),
                    StoreId = storeId,
                    CartId = userinfo.CartId.ToString(),
                    CartGoodsCount = cart.GoodsCount,
                    Token = userinfo.Id.ToString()
                },
                WalletInfo = new WalletInfo
                {
                    Id = walletinfo.Id,
                    AccessCode = walletinfo.AccessCode,
                    Cash = walletinfo.Cash,
                    Benevolence = walletinfo.Benevolence,
                    Earnings = walletinfo.Earnings,
                    YesterdayEarnings = walletinfo.YesterdayEarnings
                }
            });
        }
Пример #7
0
        public async Task <BaseApiResponse> Login([FromBody] LoginRequest request)
        {
            request.CheckNotNull(nameof(request));
            //默认账户
            if (request.Name == "admin")
            {
                if (request.Password != "wftx123456#")
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "密码不正确,登录不被允许"
                    });
                }
                //登陆
                await SignInAsync(GuidUtil.NewSequentialId().ToString(), "admin", true);

                return(new LoginResponse
                {
                    User = new User
                    {
                        Id = GuidUtil.NewSequentialId(),
                        LoginName = "admin",
                        Name = "夏某某",
                        Role = "Admin",
                        Portrait = "https://raw.githubusercontent.com/taylorchen709/markdown-images/master/vueadmin/user.png"
                    }
                });
            }
            var admin = _adminQueryService.Find(request.Name);

            //验证用户
            if (admin == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该账号"
                });
            }
            //验证账号
            if (admin.IsLocked)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "账号锁定"
                });
            }
            //验证密码
            if (!PasswordHash.ValidatePassword(request.Password, admin.Password))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "登录密码错误"
                });
            }
            await SignInAsync(admin.Id.ToString(), admin.Name, true);

            return(new LoginResponse
            {
                User = new User
                {
                    Id = admin.Id,
                    LoginName = admin.LoginName,
                    Name = admin.Name,
                    Role = admin.Role.ToString(),
                    Portrait = admin.Portrait
                }
            });
        }
Пример #8
0
        public async Task <BaseApiResponse> ShopLogin([FromBody] LoginRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (!request.Mobile.IsMobileNumber())
            {//是否手机号
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号格式不正确"
                });
            }
            var userinfo = _userQueryService.FindUser(request.Mobile);

            //验证用户
            if (userinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该账号"
                });
            }
            //验证密码
            if (!PasswordHash.ValidatePassword(request.Password, userinfo.Password))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "登录密码错误"
                });
            }


            //店铺信息
            var storeinfo = _storeQueryService.InfoByUserId(userinfo.Id);

            if (storeinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "您没有店铺"
                });
            }
            await SignInAsync(userinfo.Id.ToString(), userinfo.WalletId.ToString(), userinfo.Mobile, true);

            return(new ShopLoginResponse
            {
                UserInfo = new UserInfo
                {
                    Id = userinfo.Id,
                    NickName = userinfo.NickName,
                    Portrait = userinfo.Portrait.ToOssStyleUrl(OssImageStyles.UserPortrait.ToDescription()),
                    Mobile = userinfo.Mobile,
                    Gender = userinfo.Gender,
                    Region = userinfo.Region,
                    Role = userinfo.Role.ToDescription(),
                    StoreId = storeinfo.Id.ToString(),
                    CartId = userinfo.CartId.ToString(),
                    Token = userinfo.Id.ToString()
                },
                StoreInfo = new StoreInfo
                {
                    Id = storeinfo.Id,
                    Name = storeinfo.Name,
                    Description = storeinfo.Description,
                    Region = storeinfo.Region,
                    Address = storeinfo.Address,
                    TodayOrder = storeinfo.TodayOrder,
                    TodaySale = storeinfo.TodaySale,
                    TotalOrder = storeinfo.TotalOrder,
                    TotalSale = storeinfo.TotalSale
                },
                ReturnAddressInfo = new ReturnAddressInfo
                {
                    StoreId = storeinfo.Id,
                    Name = storeinfo.ReturnAddressName,
                    Mobile = storeinfo.ReturnAddressMobile,
                    Address = storeinfo.ReturnAddress
                }
            });
        }
Пример #9
0
        public async Task <BaseApiResponse> Login([FromBody] LoginRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (!request.Mobile.IsMobileNumber())
            {//是否手机号
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号格式不正确"
                });
            }
            var userinfo = _userQueryService.FindUser(request.Mobile);

            //验证用户
            if (userinfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该账号"
                });
            }
            //验证账号
            if (userinfo.IsLocked == UserLock.Locked)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "账号锁定"
                });
            }
            //验证密码
            if (!PasswordHash.ValidatePassword(request.Password, userinfo.Password))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "登录密码错误"
                });
            }
            try
            {
                //获取钱包信息
                var walletinfo = _walletQueryService.Info(userinfo.WalletId);
                if (walletinfo == null)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "获取钱包信息失败"
                    });
                }

                //购物车信息
                var cart = _cartQueryService.Info(userinfo.CartId);
                if (cart == null)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "获取购物车信息失败"
                    });
                }
                //店铺信息
                var storeId   = "";
                var storeinfo = _storeQueryService.InfoByUserId(userinfo.Id);
                if (storeinfo != null)
                {
                    storeId = storeinfo.Id.ToString();
                }

                await SignInAsync(userinfo.Id.ToString(), userinfo.WalletId.ToString(), userinfo.Mobile, true);

                return(new LoginResponse
                {
                    UserInfo = new UserInfo
                    {
                        Id = userinfo.Id,
                        ParentId = userinfo.ParentId,
                        NickName = userinfo.NickName,
                        Portrait = userinfo.Portrait.ToOssStyleUrl(OssImageStyles.UserPortrait.ToDescription()),
                        Mobile = userinfo.Mobile,
                        Gender = userinfo.Gender,
                        Region = userinfo.Region,
                        Role = userinfo.Role.ToDescription(),
                        StoreId = storeId,
                        CartId = userinfo.CartId.ToString(),
                        CartGoodsCount = cart.GoodsCount,
                        IsLocked = userinfo.IsLocked,
                        Token = userinfo.Id.ToString()
                    },
                    WalletInfo = new WalletInfo
                    {
                        Id = walletinfo.Id,
                        AccessCode = walletinfo.AccessCode,
                        Cash = walletinfo.Cash,
                        Benevolence = walletinfo.Benevolence,
                        Earnings = walletinfo.Earnings,
                        YesterdayEarnings = walletinfo.YesterdayEarnings,
                        IsFreeze = walletinfo.IsFreeze
                    }
                });
            }
            catch (Exception e)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = e.Message
                });
            }
        }
Пример #10
0
        public BaseApiResponse Login(LoginRequest request)
        {
            request.CheckNotNull(nameof(request));

            if (request.Name == "admin")
            {
                if (request.Password != "wftx123456~")
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "密码不正确,登录不被允许"
                    });
                }
                return(new LoginResponse
                {
                    User = new User
                    {
                        Id = GuidUtil.NewSequentialId(),
                        LoginName = "admin",
                        Name = "夏某某",
                        Password = "******",
                        Role = "admin",
                        Portrait = "https://raw.githubusercontent.com/taylorchen709/markdown-images/master/vueadmin/user.png"
                    }
                });
            }
            if (request.Name == "accountant")
            {
                if (request.Password != "wftx666!")
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "密码不正确,登录不被允许"
                    });
                }
                return(new LoginResponse
                {
                    User = new User
                    {
                        Id = GuidUtil.NewSequentialId(),
                        LoginName = "accountant",
                        Name = "财务",
                        Password = "******",
                        Role = "accountant",
                        Portrait = "https://raw.githubusercontent.com/taylorchen709/markdown-images/master/vueadmin/user.png"
                    }
                });
            }
            if (request.Name == "goodsmgr")
            {
                if (request.Password != "wftx666#")
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "密码不正确,登录不被允许"
                    });
                }
                return(new LoginResponse
                {
                    User = new User
                    {
                        Id = GuidUtil.NewSequentialId(),
                        LoginName = "goodsmgr",
                        Name = "商品审核员",
                        Password = "******",
                        Role = "goodsmgr",
                        Portrait = "https://raw.githubusercontent.com/taylorchen709/markdown-images/master/vueadmin/user.png"
                    }
                });
            }
            return(new BaseApiResponse {
                Code = 400, Message = "账号错误,登录不被允许"
            });
        }