public async Task <BaseModel <string> > LoginAsync(LoginReqDto reqDto)
        {
            BaseModel <String> result = new BaseModel <string>();
            var loginValidate         = userService.LoginCheck(reqDto.Account, reqDto.Password, LoginPlatform.Web);

            if (loginValidate.Flag)
            {
                //登录验证成功..
                //如果登录成功要先看之前有没有同账号登录,如果有的话,让他下线
                var lastLogin = GloableCache.OnlineClients.Values.Where(p => p.ClientId != null && p.User != null && p.User.Id == loginValidate.Data.Id).FirstOrDefault();
                if (lastLogin != null)
                {
                    //发消息让这个人下线.
                    await messageHub.Clients.Client(lastLogin.SignarlRId).SendAsync("CleanCookieAndExit");

                    lastLogin.User = null;
                }

                //设置缓存,cache什么的
                LoginLogic(loginValidate.Data);
                if (reqDto.RememberMe)
                {
                    SetCookies("lastAccount", reqDto.Account, 60 * 24 * 365);
                }
                result.Success("登录成功!");
            }
            else
            {
                result.Failed(loginValidate.Msg);
            }
            return(result);
        }
        public async Task <IActionResult> Register(LoginReqDto loginReq)
        {
            if (await uow.userRepository.UserAlreadyExists(loginReq.UserName))
            {
                return(BadRequest("User already exist, please try another one"));
            }
            uow.userRepository.Register(loginReq.UserName, loginReq.Password);
            await uow.SaveAsync();

            return(StatusCode(201));
        }
Esempio n. 3
0
        public async Task <IActionResult> Register(LoginReqDto loginReq)
        {
            if (await uow.UserRepository.UserAlreadyExists(loginReq.UserName))
            {
                return(BadRequest("A user already exists with that name; please try a different user name."));
            }

            uow.UserRepository.Register(loginReq.UserName, loginReq.Password);
            await uow.SaveAsync();

            return(StatusCode(201)); // record successfully added
        }
        public async Task <IActionResult> Register(LoginReqDto model)
        {
            //string pass = CommonFuntions.Decrypt("UOUx6b5VPb2e5G+X0bEVxw==");

            if (await uow.AccountRepository.UserAlreadyExists(model.UserName))
            {
                return(BadRequest("User Already Exists,Please try something else"));
            }
            uow.AccountRepository.Register(model.UserName, model.Password);
            await uow.SaveAsync();

            return(StatusCode(201));
        }
Esempio n. 5
0
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var user = await uow.UserRepository.Authenticate(loginReq.UserName, loginReq.Password);

            if (user == null)
            {
                return(Unauthorized());
            }
            var loginRes = new LoginResDto();

            loginRes.UserName = user.Username;
            loginRes.Token    = "Token to be generated";
            return(Ok(loginRes));
        }
Esempio n. 6
0
        // http://localhost:5000/api/admin/login
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var admin = await uow.AdminRepository.Authenticate(loginReq.UserName, loginReq.Password);

            if (admin == null)
            {
                return(Unauthorized());
            }
            var loginRes = new LoginResDto();

            loginRes.UserName = admin.Username;
            loginRes.Token    = CreateJWT(admin);
            return(Ok(loginRes));
        }
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var user = await unitofWork.UserRepository.Authenticate(loginReq.Username, loginReq.Password);

            if (user == null)
            {
                return(Unauthorized());
            }
            var loginRes = new LoginResDto();

            loginRes.Username = user.Username;
            loginRes.Token    = CreateJWT(user);
            return(Ok(loginRes));
        }
Esempio n. 8
0
        public ApiResult <LoginResDto> Login(LoginReqDto reqDto)
        {
            if (string.IsNullOrWhiteSpace(reqDto.Account))
            {
                throw new ApiException(16000, "参数account验证失败");
            }

            if (string.IsNullOrWhiteSpace(reqDto.Password))
            {
                throw new ApiException(16000, "参数password验证失败");
            }

            return(userInfoService.Login(reqDto, this.Request));
        }
Esempio n. 9
0
        public async Task <IActionResult> Register(LoginReqDto loginReq)
        {
            if (loginReq.UserName.IsEmpty() || loginReq.Password.IsEmpty())
            {
                return(BadRequest("User name or password can not be blank"));
            }

            if (await uow.UserRepository.UserAlreadyExists(loginReq.UserName))
            {
                return(BadRequest("User already exists, please try something else"));
            }

            uow.UserRepository.Register(loginReq.UserName, loginReq.Password);
            await uow.SaveAsync();

            return(StatusCode(201));
        }
Esempio n. 10
0
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var user = await uow.UserRepository.Authenticate(loginReq.UserName, loginReq.Password);

            if (user == null)
            {
                return(Unauthorized());
            }

            var loginResDto = new LoginResDto
            {
                UserName = user.Username,
                Token    = CreateJWT(user)
            };

            return(Ok(loginResDto));
        }
Esempio n. 11
0
        public async Task <IActionResult> Login(LoginReqDto loginReqDto)
        {
            var user = await uow.UserRepository.Authenticate(loginReqDto.Email, loginReqDto.Password);

            if (user == null)
            {
                return(Unauthorized());
            }

            var loginRes = new LoginResDto();

            loginRes.Email     = user.Email;
            loginRes.FirstName = user.FirstName;
            loginRes.LastName  = user.LastName;
            loginRes.Mobile    = user.Mobile;
            loginRes.Token     = CreateJWT(user);

            return(Ok(loginRes));
        }
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var user = await uow.UserRepository.Authenticate(loginReq.Username, loginReq.Password);

            ApiError apiError = new ApiError();

            if (user == null)
            {
                apiError.ErrorCode    = Unauthorized().StatusCode;
                apiError.ErrorMessage = "Invalid user name or password";
                return(Unauthorized(apiError));
            }

            var loginRes = new LoginResDto();

            loginRes.Username = loginReq.Username;
            loginRes.Token    = CreateJWT(user);
            return(Ok(loginRes));
        }
Esempio n. 13
0
        public async Task <IActionResult> Login(LoginReqDto loginReq)
        {
            var user = await uow.UserRepository.Authenticate(loginReq.UserName, loginReq.Password);

            ApiError apiError = new ApiError();

            if (user == null)
            {
                apiError.ErrorCode    = Unauthorized().StatusCode;
                apiError.ErrorMessage = "Nume sau parola gresita!";
                apiError.ErrorDetails = "Aceasta erroare apare cand userul si parola nu exista.";
                return(Unauthorized(apiError));
            }
            var loginRes = new LoginResponseDto();

            loginRes.UserName = user.Username;
            loginRes.Token    = CreateJWT(user);
            return(Ok(loginRes));
        }
Esempio n. 14
0
        public async Task <IActionResult> Register(LoginReqDto loginReq)
        {
            ApiError apiError = new ApiError();

            if (loginReq.UserName.IsEmpty() || loginReq.Password.IsEmpty())
            {
                apiError.ErrorCode    = BadRequest().StatusCode;
                apiError.ErrorMessage = "User name or password can not be blank";
                return(BadRequest(apiError));
            }

            if (await uow.UserRepository.UserAlreadyExists(loginReq.UserName))
            {
                apiError.ErrorCode    = BadRequest().StatusCode;
                apiError.ErrorMessage = "User already exists, please try different user name";
                return(BadRequest(apiError));
            }

            uow.UserRepository.Register(loginReq.UserName, loginReq.Password);
            await uow.SaveAsync();

            return(StatusCode(201));
        }
Esempio n. 15
0
        public ApiResult <LoginResDto> Login(LoginReqDto reqDto, HttpRequestMessage request)
        {
            UserInfoService service     = new UserInfoService();
            UserInfo        accountInfo = service.GetFullUserInfoByMobile(reqDto.Account);

            if (accountInfo == null)
            {
                throw new ApiException(15023, "用户名不存在或密码错误");
            }

            if (accountInfo.Password.StartsWith("$2y"))
            {
                if (!Crypter.CheckPassword(reqDto.Password, accountInfo.Password))
                {
                    throw new ApiException(15023, "用户名不存在或密码错误");
                }
            }
            else
            {
                if (Tool.GetMD5(reqDto.Password) != accountInfo.Password)
                {
                    throw new ApiException(15023, "用户名不存在或密码错误");
                }
            }

            string webHost = ConfigurationManager.AppSettings["webHost"];
            string avater  = string.IsNullOrWhiteSpace(accountInfo.Avater)
                ? string.Format("{0}/images/default_avater.png", webHost)
                : accountInfo.Avater;

            LoginResDto resDto = new LoginResDto()
            {
                Account  = accountInfo.Mobile,
                Avater   = avater,
                UserId   = accountInfo.Id,
                Mobile   = accountInfo.Mobile,
                NickName = accountInfo.NickName
            };

            #region  发登录token

            IdentityInfo authInfo = new IdentityInfo()
            {
                UserId      = accountInfo.Id,
                UserAccount = accountInfo.Mobile,
                UserStatus  = (int)accountInfo.State,
                UserName    = accountInfo.NickName,
                IsTemp      = false,
                Avater      = avater
            };

            var tokenAuth = new QiuxunTokenAuthorizer(new ApiAuthContainer(request));
            tokenAuth.Authorize(authInfo);

            #endregion

            return(new ApiResult <LoginResDto>()
            {
                Data = resDto
            });
        }