Exemplo n.º 1
0
        public virtual async Task <ActionResult> ResetPassword(ResetPasswordFormViewModel model)
        {
            this.CheckModelState();
            IActiveUnitOfWork current = this._unitOfWorkManager.Current;

            current.DisableFilter(new string[] { "MayHaveTenant" });
            long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8"));

            FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num);

            if (userByIdAsync == null || userByIdAsync.PasswordResetCode.IsNullOrEmpty() || userByIdAsync.PasswordResetCode != model.ResetCode)
            {
                throw new UserFriendlyException(this.L("InvalidPasswordResetCode"), this.L("InvalidPasswordResetCode_Detail"));
            }
            userByIdAsync.Password          = (new PasswordHasher()).HashPassword(model.Password);
            userByIdAsync.PasswordResetCode = null;
            userByIdAsync.IsEmailConfirmed  = true;
            userByIdAsync.ShouldChangePasswordOnNextLogin = false;
            await this._userManager.UpdateAsync(userByIdAsync);

            if (userByIdAsync.IsActive)
            {
                await this.SignInAsync(userByIdAsync, null, false);
            }
            return(this.RedirectToAction("Index", "Application"));
        }
Exemplo n.º 2
0
        public virtual async Task <ActionResult> EmailConfirmation(EmailConfirmationViewModel model)
        {
            string tenancyName;

            this.CheckModelState();
            IActiveUnitOfWork current = this._unitOfWorkManager.Current;

            current.DisableFilter(new string[] { "MayHaveTenant" });
            long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8"));

            FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num);

            if (userByIdAsync == null || userByIdAsync.EmailConfirmationCode.IsNullOrEmpty() || userByIdAsync.EmailConfirmationCode != model.ConfirmationCode)
            {
                throw new UserFriendlyException(this.L("InvalidEmailConfirmationCode"), this.L("InvalidEmailConfirmationCode_Detail"));
            }
            userByIdAsync.IsEmailConfirmed      = true;
            userByIdAsync.EmailConfirmationCode = null;
            await this._userManager.UpdateAsync(userByIdAsync);

            if (!userByIdAsync.TenantId.HasValue)
            {
                tenancyName = "";
            }
            else
            {
                TenantManager tenantManager = this._tenantManager;
                int?          tenantId      = userByIdAsync.TenantId;
                tenancyName = (await tenantManager.GetByIdAsync(tenantId.Value)).TenancyName;
            }
            string       str    = tenancyName;
            ActionResult action = this.RedirectToAction("Login", new { successMessage = this.L("YourEmailIsConfirmedMessage"), tenancyName = str, userNameOrEmailAddress = userByIdAsync.UserName });

            return(action);
        }
Exemplo n.º 3
0
        public virtual async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            Guid guid;
            Guid guid1;

            this.CheckModelState();
            IActiveUnitOfWork current = this._unitOfWorkManager.Current;

            current.DisableFilter(new string[] { "MayHaveTenant" });
            long num = Convert.ToInt64(SimpleStringCipher.Decrypt(model.UserId, "gsKnGZ041HLL4IM8"));

            FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(num);

            if (userByIdAsync == null || userByIdAsync.PasswordResetCode.IsNullOrEmpty() || userByIdAsync.PasswordResetCode != model.ResetCode)
            {
                throw new UserFriendlyException(this.L("InvalidPasswordResetCode"), this.L("InvalidPasswordResetCode_Detail"));
            }
            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;
            return(this.View(model));
        }
Exemplo n.º 4
0
        public virtual async Task <JsonResult> ChangeProfilePicture()
        {
            JsonResult jsonResult;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("ProfilePicture_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("ProfilePicture_Warn_SizeLimit"));
                }
                FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(this.AbpSession.GetUserId());

                FuelWerx.Authorization.Users.User nullable = userByIdAsync;
                if (nullable.ProfilePictureId.HasValue)
                {
                    await this._binaryObjectManager.DeleteAsync(nullable.ProfilePictureId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.ProfilePictureId = new Guid?(binaryObject.Id);
                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
Exemplo n.º 5
0
        public async Task <PartialViewResult> PermissionsModal(long id)
        {
            FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(id);

            GetUserPermissionsForEditOutput userPermissionsForEdit = await this._userAppService.GetUserPermissionsForEdit(new IdInput <long>(id));

            return(this.PartialView("_PermissionsModal", new UserPermissionsEditViewModel(userPermissionsForEdit, userByIdAsync)));
        }
Exemplo n.º 6
0
        public virtual async Task <JsonResult> SendEmailActivationLink(SendEmailActivationLinkViewModel model)
        {
            IActiveUnitOfWork current = this._unitOfWorkManager.Current;

            current.DisableFilter(new string[] { "MayHaveTenant" });
            FuelWerx.Authorization.Users.User userByChecking = await this.GetUserByChecking(model.EmailAddress, model.TenancyName);

            FuelWerx.Authorization.Users.User user = userByChecking;
            user.SetNewEmailConfirmationCode();
            await this._userEmailer.SendEmailActivationLinkAsync(user, null);

            return(this.Json(new MvcAjaxResponse()));
        }
Exemplo n.º 7
0
        private async Task SignInAsync(FuelWerx.Authorization.Users.User user, ClaimsIdentity identity = null, bool rememberMe = false)
        {
            if (identity == null)
            {
                identity = await this._userManager.CreateIdentityAsync(user, "ApplicationCookie");
            }
            this.AuthenticationManager.SignOut(new string[] { "ApplicationCookie" });
            IAuthenticationManager   authenticationManager  = this.AuthenticationManager;
            AuthenticationProperties authenticationProperty = new AuthenticationProperties()
            {
                IsPersistent = rememberMe
            };

            authenticationManager.SignIn(authenticationProperty, new ClaimsIdentity[] { identity });
        }
Exemplo n.º 8
0
        private async Task <FuelWerx.Authorization.Users.User> GetUserByChecking(string emailAddress, string tenancyName)
        {
            int?tenantIdOrDefault = await this.GetTenantIdOrDefault(tenancyName);

            IQueryable <FuelWerx.Authorization.Users.User> users = this._userManager.Users;

            FuelWerx.Authorization.Users.User user = await(
                from u in users
                where u.EmailAddress == emailAddress && u.TenantId == tenantIdOrDefault
                select u).FirstOrDefaultAsync <FuelWerx.Authorization.Users.User>();
            FuelWerx.Authorization.Users.User user1 = user;
            if (user1 == null)
            {
                throw new UserFriendlyException(this.L("InvalidEmailAddress"));
            }
            return(user1);
        }
Exemplo n.º 9
0
        public async Task <FileResult> GetProfilePicture()
        {
            FileResult profilePictureById;

            FuelWerx.Authorization.Users.User userByIdAsync = await this._userManager.GetUserByIdAsync(this.AbpSession.GetUserId());

            FuelWerx.Authorization.Users.User user = userByIdAsync;
            if (user.ProfilePictureId.HasValue)
            {
                profilePictureById = await this.GetProfilePictureById(user.ProfilePictureId.Value);
            }
            else
            {
                profilePictureById = this.GetDefaultProfilePicture();
            }
            return(profilePictureById);
        }
Exemplo n.º 10
0
        public virtual async Task <ActionResult> ImpersonateSignIn(string tokenId)
        {
            ActionResult           action;
            ImpersonationCacheItem orDefaultAsync = await this._cacheManager.GetImpersonationCache().GetOrDefaultAsync(tokenId);

            ImpersonationCacheItem impersonationCacheItem = orDefaultAsync;

            if (impersonationCacheItem == null)
            {
                throw new UserFriendlyException(this.L("ImpersonationTokenErrorMessage"));
            }
            using (IDisposable disposable = this._unitOfWorkManager.Current.SetFilterParameter("MayHaveTenant", "tenantId", impersonationCacheItem.TargetTenantId))
            {
                FuelWerx.Authorization.Users.User user = await this._userManager.FindByIdAsync(impersonationCacheItem.TargetUserId);

                ClaimsIdentity claimsIdentity = await this._userManager.CreateIdentityAsync(user, "ApplicationCookie");

                if (!impersonationCacheItem.IsBackToImpersonator)
                {
                    if (impersonationCacheItem.ImpersonatorTenantId.HasValue)
                    {
                        int value = impersonationCacheItem.ImpersonatorTenantId.Value;
                        claimsIdentity.AddClaim(new Claim("http://www.aspnetboilerplate.com/identity/claims/impersonatorTenantId", value.ToString(CultureInfo.InvariantCulture)));
                    }
                    long impersonatorUserId = impersonationCacheItem.ImpersonatorUserId;
                    claimsIdentity.AddClaim(new Claim("http://www.aspnetboilerplate.com/identity/claims/impersonatorUserId", impersonatorUserId.ToString(CultureInfo.InvariantCulture)));
                }
                this.AuthenticationManager.SignOut(new string[] { "ApplicationCookie" });
                IAuthenticationManager   authenticationManager  = this.AuthenticationManager;
                AuthenticationProperties authenticationProperty = new AuthenticationProperties()
                {
                    IsPersistent = false
                };
                authenticationManager.SignIn(authenticationProperty, new ClaimsIdentity[] { claimsIdentity });
                await this._cacheManager.GetImpersonationCache().RemoveAsync(tokenId);

                action = this.RedirectToAction("Index", "Application");
            }
            return(action);
        }
Exemplo n.º 11
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            ActionResult actionResult;

            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult loginResultAsync;
            Guid guid;
            Guid guid1;
            bool flag;

            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult;
            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;
            try
            {
                this.CheckSelfRegistrationIsEnabled();
                this.CheckModelState();
                if (!model.IsExternalLogin && this.UseCaptchaOnRegistration())
                {
                    RecaptchaVerificationHelper recaptchaVerificationHelper = this.GetRecaptchaVerificationHelper();
                    if (recaptchaVerificationHelper.Response.IsNullOrEmpty())
                    {
                        throw new UserFriendlyException(this.L("CaptchaCanNotBeEmpty"));
                    }
                    if (recaptchaVerificationHelper.VerifyRecaptchaResponse() != RecaptchaVerificationResult.Success)
                    {
                        throw new UserFriendlyException(this.L("IncorrectCaptchaAnswer"));
                    }
                }
                if (!this._multiTenancyConfig.IsEnabled)
                {
                    model.TenancyName = "Default";
                }
                else if (model.TenancyName.IsNullOrEmpty())
                {
                    throw new UserFriendlyException(this.L("TenantNameCanNotBeEmpty"));
                }
                Tenant activeTenantAsync = await this.GetActiveTenantAsync(model.TenancyName);

                bool settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "App.UserManagement.AllowSelfRegistration", activeTenantAsync.Id);

                if (!settingValueForTenantAsync)
                {
                    throw new UserFriendlyException(this.L("SelfUserRegistrationIsDisabledMessage_Detail"));
                }
                settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "App.UserManagement.IsNewRegisteredUserActiveByDefault", activeTenantAsync.Id);

                bool flag1 = settingValueForTenantAsync;
                settingValueForTenantAsync = await SettingManagerExtensions.GetSettingValueForTenantAsync <bool>(this.SettingManager, "Abp.Zero.UserManagement.IsEmailConfirmationRequiredForLogin", activeTenantAsync.Id);

                bool flag2 = settingValueForTenantAsync;
                FuelWerx.Authorization.Users.User user = new FuelWerx.Authorization.Users.User()
                {
                    TenantId     = new int?(activeTenantAsync.Id),
                    Name         = model.Name,
                    Surname      = model.Surname,
                    EmailAddress = model.EmailAddress,
                    IsActive     = flag1
                };
                FuelWerx.Authorization.Users.User userName = user;
                ExternalLoginInfo externalLoginInfoAsync   = null;
                if (model.IsExternalLogin)
                {
                    externalLoginInfoAsync = await AuthenticationManagerExtensions.GetExternalLoginInfoAsync(this.AuthenticationManager);

                    if (externalLoginInfoAsync == null)
                    {
                        throw new ApplicationException("Can not external login!");
                    }
                    FuelWerx.Authorization.Users.User user1 = userName;
                    List <UserLogin> userLogins             = new List <UserLogin>();
                    UserLogin        userLogin = new UserLogin()
                    {
                        LoginProvider = externalLoginInfoAsync.Login.LoginProvider,
                        ProviderKey   = externalLoginInfoAsync.Login.ProviderKey
                    };
                    userLogins.Add(userLogin);
                    user1.Logins   = userLogins;
                    model.UserName = model.EmailAddress;
                    model.Password = FuelWerx.Authorization.Users.User.CreateRandomPassword();
                    if (string.Equals(externalLoginInfoAsync.Email, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase))
                    {
                        userName.IsEmailConfirmed = true;
                    }
                }
                else if (model.UserName.IsNullOrEmpty() || model.Password.IsNullOrEmpty())
                {
                    throw new UserFriendlyException(this.L("FormIsNotValidMessage"));
                }
                userName.UserName = model.UserName;
                userName.Password = (new PasswordHasher()).HashPassword(model.Password);
                IActiveUnitOfWork current = this._unitOfWorkManager.Current;
                current.EnableFilter(new string[] { "MayHaveTenant" });
                this._unitOfWorkManager.Current.SetFilterParameter("MayHaveTenant", "tenantId", activeTenantAsync.Id);
                userName.Roles = new List <UserRole>();
                IQueryable <Role> roles     = this._roleManager.Roles;
                List <Role>       listAsync = await(
                    from r in roles
                    where r.IsDefault
                    select r).ToListAsync <Role>();
                foreach (Role role in listAsync)
                {
                    ICollection <UserRole> userRoles = userName.Roles;
                    userRoles.Add(new UserRole()
                    {
                        RoleId = role.Id
                    });
                }
                this.CheckErrors(await this._userManager.CreateAsync(userName));
                await this._unitOfWorkManager.Current.SaveChangesAsync();

                if (!userName.IsEmailConfirmed)
                {
                    userName.SetNewEmailConfirmationCode();
                    await this._userEmailer.SendEmailActivationLinkAsync(userName, null);
                }
                if (userName.IsActive && (userName.IsEmailConfirmed || !flag2))
                {
                    if (externalLoginInfoAsync == null)
                    {
                        loginResultAsync = await this.GetLoginResultAsync(userName.UserName, model.Password, activeTenantAsync.TenancyName);

                        abpLoginResult = loginResultAsync;
                    }
                    else
                    {
                        loginResultAsync = await this._userManager.LoginAsync(externalLoginInfoAsync.Login, activeTenantAsync.TenancyName);

                        abpLoginResult = loginResultAsync;
                    }
                    if (abpLoginResult.Result != AbpLoginResultType.Success)
                    {
                        this.Logger.Warn(string.Concat("New registered user could not be login. This should not be normally. login result: ", abpLoginResult.Result));
                        abpLoginResult = null;
                    }
                    else
                    {
                        await this.SignInAsync(abpLoginResult.User, abpLoginResult.Identity, false);

                        actionResult = this.Redirect(this.Url.Action("Index", "Application"));
                        return(actionResult);
                    }
                }
                AccountController       accountController       = this;
                RegisterResultViewModel registerResultViewModel = new RegisterResultViewModel()
                {
                    TenancyName    = activeTenantAsync.TenancyName,
                    NameAndSurname = string.Concat(userName.Name, " ", userName.Surname),
                    UserName       = userName.UserName,
                    EmailAddress   = userName.EmailAddress,
                    IsActive       = userName.IsActive,
                    IsEmailConfirmationRequired = flag2
                };
                actionResult = accountController.View("RegisterResult", registerResultViewModel);
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                ((dynamic)this.ViewBag).IsMultiTenancyEnabled = this._multiTenancyConfig.IsEnabled;
                dynamic viewBag1 = this.ViewBag;
                flag = (model.IsExternalLogin ? false : this.UseCaptchaOnRegistration());
                viewBag1.UseCaptcha = flag;
                ((dynamic)this.ViewBag).ErrorMessage = userFriendlyException.Message;
                actionResult = this.View("Register", model);
            }
            return(actionResult);
        }
Exemplo n.º 12
0
        public virtual async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "")
        {
            JsonResult jsonResult;

            this.CheckModelState();
            IActiveUnitOfWork current = this._unitOfWorkManager.Current;

            current.DisableFilter(new string[] { "MayHaveTenant" });
            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult loginResultAsync = await this.GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName);

            AbpUserManager <Tenant, Role, FuelWerx.Authorization.Users.User> .AbpLoginResult abpLoginResult = loginResultAsync;
            if (!abpLoginResult.User.ShouldChangePasswordOnNextLogin)
            {
                await this.SignInAsync(abpLoginResult.User, abpLoginResult.Identity, loginModel.RememberMe);

                if (string.IsNullOrWhiteSpace(returnUrl))
                {
                    returnUrl = this.Url.Action("Index", "Application");
                }
                if (!string.IsNullOrWhiteSpace(returnUrlHash))
                {
                    returnUrl = string.Concat(returnUrl, returnUrlHash);
                }
                FuelWerx.Authorization.Users.User user = await this._userManager.FindByNameOrEmailAsync(loginModel.UsernameOrEmailAddress.ToString());

                FuelWerx.Authorization.Users.User user1 = user;
                if (user1 != null)
                {
                    string userPostLoginViewType = await this._userAppService.GetUserPostLoginViewType(user1.Id);

                    if (!string.IsNullOrEmpty(userPostLoginViewType))
                    {
                        this.Session.Add("PostLoginRedirectCheck", userPostLoginViewType);
                    }
                    bool flag = await this._userAppService.ShowScreencastAtLogin(user1.Id);

                    if (flag)
                    {
                        this.Session.Add("ShowScreencastAtLoginCheck", flag);
                    }
                }
                AccountController accountController = this;
                MvcAjaxResponse   mvcAjaxResponse   = new MvcAjaxResponse()
                {
                    TargetUrl = returnUrl
                };
                jsonResult = accountController.Json(mvcAjaxResponse);
            }
            else
            {
                abpLoginResult.User.SetNewPasswordResetCode();
                AccountController      accountController1 = this;
                MvcAjaxResponse        mvcAjaxResponse1   = new MvcAjaxResponse();
                UrlHelper              url = this.Url;
                ResetPasswordViewModel resetPasswordViewModel = new ResetPasswordViewModel();
                long id = abpLoginResult.User.Id;
                resetPasswordViewModel.UserId    = SimpleStringCipher.Encrypt(id.ToString(), "gsKnGZ041HLL4IM8");
                resetPasswordViewModel.ResetCode = abpLoginResult.User.PasswordResetCode;
                mvcAjaxResponse1.TargetUrl       = url.Action("ResetPassword", resetPasswordViewModel);
                jsonResult = accountController1.Json(mvcAjaxResponse1);
            }
            return(jsonResult);
        }
Exemplo n.º 13
0
 public UserPermissionsEditViewModel(GetUserPermissionsForEditOutput output, FuelWerx.Authorization.Users.User user)
 {
     this.User = user;
     output.MapTo <GetUserPermissionsForEditOutput, UserPermissionsEditViewModel>(this);
 }