Exemple #1
0
        public Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                return(new Exception("Don't call this method with a success result!"));

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                return(new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword")));

            case AbpLoginResultType.InvalidTenancyName:
                return(new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)));

            case AbpLoginResultType.TenantIsNotActive:
                return(new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName)));

            case AbpLoginResultType.UserIsNotActive:
                return(new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)));

            case AbpLoginResultType.UserEmailIsNotConfirmed:
                return(new UserFriendlyException(L("LoginFailed"), L("UserEmailIsNotConfirmedAndCanNotLogin")));

            case AbpLoginResultType.LockedOut:
                return(new UserFriendlyException(L("LoginFailed"), L("UserLockedOutMessage")));

            default:     // Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
                Logger.Warn("Unhandled login fail reason: " + result);
                return(new UserFriendlyException(L("LoginFailed")));
            }
        }
        private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress,
                                                               string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                return(new UserFriendlyException("不要用这个方法调用成功的结果!"));

            case AbpLoginResultType.InvalidUserNameOrEmailAddress: //无效用户名或电子邮箱
            case AbpLoginResultType.InvalidPassword:               //无效密码
                return(new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword")));

            case AbpLoginResultType.InvalidTenancyName:    //无效的租户名称
                return(new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)));

            case AbpLoginResultType.TenantIsNotActive:    //租户未激活
                return(new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName)));

            case AbpLoginResultType.UserIsNotActive:    //用户没激活
                return(new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)));

            case AbpLoginResultType.UserEmailIsNotConfirmed:                                //用户邮箱未确认
                return(new UserFriendlyException(L("LoginFailed"), "您的电子邮件地址未被确认。 你不能登录")); //TODO: 本地化消息

            default:                                                                        //实际上不能落到默认值。 但是其他结果类型可以在将来添加,我们可能会忘记处理它
                Logger.Warn("未处理的登录失败原因: " + result);
                return(new UserFriendlyException(L("LoginFailed")));
            }
        }
Exemple #3
0
        private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string userName, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                return(new ApplicationException("Don't call this method with a success result!"));

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                return(new UserFriendlyException(L("登录失败"), L("用户名或者密码错误")));

            case AbpLoginResultType.InvalidTenancyName:
                return(new UserFriendlyException(L("登录失败"), L("当前用户不属于任何运营商{0}", tenancyName)));

            case AbpLoginResultType.TenantIsNotActive:
                return(new UserFriendlyException(L("登录失败"), L("所属运营商已经已过期", tenancyName)));

            case AbpLoginResultType.UserIsNotActive:
                return(new UserFriendlyException(L("登录失败"), L("用户已经被禁止登录", userName)));

            case AbpLoginResultType.UserEmailIsNotConfirmed:
                return(new UserFriendlyException(L("登录失败"), "电子邮件没有验证通过"));

            default:
                Logger.Warn("Unhandled login fail reason: " + result);
                return(new UserFriendlyException(L("登录失败")));
            }
        }
        private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                return(new ApplicationException("Don't call this method with a success result!"));

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                return(new UserFriendlyException(L("登录失败"), L("账号或密码错误")));

            case AbpLoginResultType.InvalidTenancyName:
                return(new UserFriendlyException(L("登录失败"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)));

            case AbpLoginResultType.TenantIsNotActive:
                return(new UserFriendlyException(L("登录失败"), L("TenantIsNotActive", tenancyName)));

            case AbpLoginResultType.UserIsNotActive:
                return(new UserFriendlyException(L("登录失败"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)));

            case AbpLoginResultType.UserEmailIsNotConfirmed:
                return(new UserFriendlyException(L("登录失败"), "Your email address is not confirmed. You can not login")); //TODO: localize message

            default:                                                                                                    //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
                Logger.Warn("Unhandled login fail reason: " + result);
                return(new UserFriendlyException(L("登录失败")));
            }
        }
Exemple #5
0
        private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            var title = "登录失败";

            switch (result)
            {
            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                return(new UserFriendlyException(title, "用户名或密码无效"));

            case AbpLoginResultType.UserIsNotActive:
                return(new UserFriendlyException(title, string.Format("用户 {0} 未激活,不能登录.", usernameOrEmailAddress)));

            case AbpLoginResultType.LockedOut:
                return(new UserFriendlyException(title, "该用户帐户已经被锁定.请稍后重试."));

            default:
                Logger.Warn("Unhandled login fail reason: " + result);
                return(new UserFriendlyException(title));
            }
        }
 private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
 {
     switch (result)
     {
         case AbpLoginResultType.Success:
             return new ApplicationException("Don't call this method with a success result!");
         case AbpLoginResultType.InvalidUserNameOrEmailAddress:
         case AbpLoginResultType.InvalidPassword:
             return new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword"));
         case AbpLoginResultType.InvalidTenancyName:
             return new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName));
         case AbpLoginResultType.TenantIsNotActive:
             return new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName));
         case AbpLoginResultType.UserIsNotActive:
             return new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress));
         case AbpLoginResultType.UserEmailIsNotConfirmed:
             return new UserFriendlyException(L("LoginFailed"), "Your email address is not confirmed. You can not login"); //TODO: localize message
         default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
             Logger.Warn("Unhandled login fail reason: " + result);
             return new UserFriendlyException(L("LoginFailed"));
     }
 }
        private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
            {
                return(new ApplicationException("Don't call this method with a success result!"));
            }

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
            {
                return(new UserFriendlyException(this.L("LoginFailed"), this.L("InvalidUserNameOrPassword")));
            }

            case AbpLoginResultType.UserIsNotActive:
            {
                return(new UserFriendlyException(this.L("LoginFailed"), base.L("UserIsNotActiveAndCanNotLogin", new object[] { usernameOrEmailAddress })));
            }

            case AbpLoginResultType.InvalidTenancyName:
            {
                return(new UserFriendlyException(this.L("LoginFailed"), base.L("ThereIsNoTenantDefinedWithName{0}", new object[] { tenancyName })));
            }

            case AbpLoginResultType.TenantIsNotActive:
            {
                return(new UserFriendlyException(this.L("LoginFailed"), base.L("TenantIsNotActive", new object[] { tenancyName })));
            }

            case AbpLoginResultType.UserEmailIsNotConfirmed:
            {
                return(new UserFriendlyException(this.L("LoginFailed"), this.L("UserEmailIsNotConfirmedAndCanNotLogin")));
            }
            }
            base.Logger.Warn(string.Concat("Unhandled login fail reason: ", result));
            return(new UserFriendlyException(this.L("LoginFailed")));
        }
        private void CreateExceptionForFailedLoginAttempt(OAuthGrantResourceOwnerCredentialsContext context,
                                                          AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                throw new ApplicationException("Don't call this method with a success result!");

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                context.SetError(L("LoginFailed"), L("InvalidUserNameOrPassword"));
                break;

            //    return new UserFriendlyException(("LoginFailed"), ("InvalidUserNameOrPassword"));
            case AbpLoginResultType.InvalidTenancyName:
                context.SetError(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName", tenancyName));
                break;

            //    return new UserFriendlyException(("LoginFailed"), string.Format("ThereIsNoTenantDefinedWithName{0}", tenancyName));
            case AbpLoginResultType.TenantIsNotActive:
                context.SetError(L("LoginFailed"), L("TenantIsNotActive", tenancyName));
                break;

            //    return new UserFriendlyException(("LoginFailed"), string.Format("TenantIsNotActive {0}", tenancyName));
            case AbpLoginResultType.UserIsNotActive:
                context.SetError(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress));
                break;

            //    return new UserFriendlyException(("LoginFailed"), string.Format("UserIsNotActiveAndCanNotLogin {0}", usernameOrEmailAddress));
            case AbpLoginResultType.UserEmailIsNotConfirmed:
                context.SetError(L("LoginFailed"), L("UserEmailIsNotConfirmedAndCanNotLogin"));
                break;
                //    return new UserFriendlyException(("LoginFailed"), ("UserEmailIsNotConfirmedAndCanNotLogin"));
                //default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
                //    //Logger.Warn("Unhandled login fail reason: " + result);
                //    return new UserFriendlyException(("LoginFailed"));
            }
        }
        private async Task SendConfirmationMail(string userName, AbpLoginResultType loginResultType, string tenancyName)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(a => a.UserName == userName);

            if (user == null)
            {
                throw CreateExceptionForFailedLoginAttempt(loginResultType, userName, tenancyName);
            }
            var token = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var confirmationUrl = Url.Action("EmailConfirmation", new
            {
                userId = user.Id,
                token  = token
            });

            if (HttpContext.Request.Url != null)
            {
                var strUrl = ServerUrl;
                var trueConfirmationUrl = "  <a href='" + strUrl + confirmationUrl + "'>" + L("ClickHereToConfirm") + "<a>";
                await _userAppService.SendEmailConfirmationCode(trueConfirmationUrl, user.EmailAddress);
            }
        }
        private void CreateExceptionForFailedLoginAttempt(OAuthGrantResourceOwnerCredentialsContext context, AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
            case AbpLoginResultType.Success:
                throw new ApplicationException("Don't call this method with a success result!");

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
            case AbpLoginResultType.InvalidPassword:
                context.SetError("LoginFailed", "InvalidUserNameOrPassword");
                break;

            case AbpLoginResultType.InvalidTenancyName:
                context.SetError("LoginFailed", "ThereIsNoTenantDefinedWithName", tenancyName);
                break;

            case AbpLoginResultType.TenantIsNotActive:
                context.SetError("LoginFailed", "TenantIsNotActive", tenancyName);
                break;

            case AbpLoginResultType.UserIsNotActive:
                context.SetError("LoginFailed", "UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress);
                break;

            case AbpLoginResultType.UserEmailIsNotConfirmed:
                context.SetError("LoginFailed", "UserEmailIsNotConfirmedAndCanNotLogin");
                break;
            }
        }
Exemple #11
0
 public JKLoginResult(AbpLoginResultType result, TUser user = null)
 {
     Result = result;
     User   = user;
 }
 public AbpLoginResult(AbpLoginResultType result)
 {
     Result = result;
 }
 public AbpLoginResult(AbpLoginResultType result, TTenant tenant = null, TUser user = null)
 {
     Result = result;
     Tenant = tenant;
     User   = user;
 }
        private ErrorInfo CreateErrorInfoForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress)
        {
            ErrorInfo info = new ErrorInfo(500);
            
            switch (result)
            {
                case AbpLoginResultType.Success:
                    throw new ApplicationException("Don't call this method with a success result!");
                case AbpLoginResultType.InvalidUserNameOrEmailAddress:
                case AbpLoginResultType.InvalidPassword:
                    info.Message = L("LoginFailed");
                    info.Details = L("InvalidUserNameOrPassword");
                    break;

                case AbpLoginResultType.UserIsNotActive:
                    info.Message = L("LoginFailed");
                    info.Details = L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress);
                    break;

                case AbpLoginResultType.UserEmailIsNotConfirmed:
                    info.Message = L("LoginFailed");
                    info.Details = "Your email address is not confirmed. You can not login";
                    break;
                    
                default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
                    Logger.Warn("Unhandled login fail reason: " + result);
                    
                    info.Message = L("LoginFailed");
                    info.Details = "Unhandled login fail reason: " + result;
                    break;
            }

            return info;
        }
Exemple #15
0
 public LoginResult(AbpLoginResultType result, TUser user = null)
 {
     this.Result = result;
     this.User   = user;
 }
 public TalentLoginResult(AbpLoginResultType result) : base(result)
 {
 }
Exemple #17
0
        public virtual async Task <ActionResult> ExternalLoginCallback(string returnUrl, string tenancyName = "")
        {
            ActionResult      action;
            ActionResult      actionResult;
            Guid              guid;
            Guid              guid1;
            ExternalLoginInfo externalLoginInfoAsync = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

            if (externalLoginInfoAsync != null)
            {
                if (tenancyName.IsNullOrEmpty())
                {
                    tenancyName = this._tenancyNameFinder.GetCurrentTenancyNameOrNull();
                    if (tenancyName.IsNullOrEmpty())
                    {
                        List <Tenant> tenants = await this.FindPossibleTenantsOfUserAsync(externalLoginInfoAsync.Login);

                        int count = tenants.Count;
                        if (count == 0)
                        {
                            actionResult = await this.RegisterView(externalLoginInfoAsync, null);

                            action = actionResult;
                            return(action);
                        }
                        else if (count == 1)
                        {
                            tenancyName = tenants[0].TenancyName;
                            tenants     = null;
                        }
                        else
                        {
                            TenantLogosEditDto tenantLogosEditDto = Abp.Threading.AsyncHelper.RunSync <TenantLogosEditDto>(() => this.GetCurrentTenantLogos());
                            dynamic            viewBag            = this.ViewBag;
                            guid = (tenantLogosEditDto.HeaderImageId.HasValue ? tenantLogosEditDto.HeaderImageId.Value : Guid.Empty);
                            viewBag.TenantCompanyHeaderImageId = guid;
                            dynamic obj = this.ViewBag;
                            guid1 = (tenantLogosEditDto.HeaderMobileImageId.HasValue ? tenantLogosEditDto.HeaderMobileImageId.Value : Guid.Empty);
                            obj.TenantCompanyHeaderMobileImageId = guid1;
                            AccountController        accountController        = this;
                            TenantSelectionViewModel tenantSelectionViewModel = new TenantSelectionViewModel()
                            {
                                Action  = this.Url.Action("ExternalLoginCallback", "Account", new { returnUrl = returnUrl }),
                                Tenants = tenants.MapTo <List <TenantSelectionViewModel.TenantInfo> >()
                            };
                            action = accountController.View("TenantSelection", tenantSelectionViewModel);
                            return(action);
                        }
                    }
                }
                AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult = await this._userManager.LoginAsync(externalLoginInfoAsync.Login, tenancyName);

                AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult1 = abpLoginResult;
                AbpLoginResultType result = abpLoginResult1.Result;
                if (result == AbpLoginResultType.Success)
                {
                    await this.SignInAsync(abpLoginResult1.User, abpLoginResult1.Identity, false);

                    if (string.IsNullOrWhiteSpace(returnUrl))
                    {
                        returnUrl = this.Url.Action("Index", "Application");
                    }
                    action = this.Redirect(returnUrl);
                }
                else
                {
                    if (result != AbpLoginResultType.UnknownExternalLogin)
                    {
                        AccountController  accountController1 = this;
                        AbpLoginResultType abpLoginResultType = abpLoginResult1.Result;
                        string             email = externalLoginInfoAsync.Email;
                        if (email == null)
                        {
                            email = externalLoginInfoAsync.DefaultUserName;
                        }
                        throw accountController1.CreateExceptionForFailedLoginAttempt(abpLoginResultType, email, tenancyName);
                    }
                    actionResult = await this.RegisterView(externalLoginInfoAsync, tenancyName);

                    action = actionResult;
                }
            }
            else
            {
                action = this.RedirectToAction("Login");
            }
            return(action);
        }