Example #1
0
        public virtual async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "")
        {
            CheckModelState();

            _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant);

            var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName);

            if (loginResult.User.ShouldChangePasswordOnNextLogin)
            {
                loginResult.User.SetNewPasswordResetCode();

                return(Json(new MvcAjaxResponse
                {
                    TargetUrl = Url.Action(
                        "ResetPassword",
                        new ResetPasswordViewModel
                    {
                        UserId = SimpleStringCipher.Encrypt(loginResult.User.Id.ToString()),
                        ResetCode = loginResult.User.PasswordResetCode
                    })
                }));
            }

            await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe);

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = Url.Action("Index", "Application");
            }

            return(Json(new MvcAjaxResponse {
                TargetUrl = returnUrl
            }));
        }
Example #2
0
        public async Task SendEmailActivationLinkAsync(User user, string plainPassword = null)
        {
            string tenancyName;

            if (user.EmailConfirmationCode.IsNullOrEmpty())
            {
                throw new ApplicationException("EmailConfirmationCode should be set in order to send email activation link.");
            }
            if (user.TenantId.HasValue)
            {
                IRepository <Tenant> repository = this._tenantRepository;
                tenancyName = repository.Get(user.TenantId.Value).TenancyName;
            }
            else
            {
                tenancyName = null;
            }
            string str = tenancyName;

            string[] siteRootAddress = new string[] { this._webUrlService.GetSiteRootAddress(str), "Account/EmailConfirmation?userId=", null, null, null };
            long     id = user.Id;

            siteRootAddress[2] = Uri.EscapeDataString(SimpleStringCipher.Encrypt(id.ToString(), "gsKnGZ041HLL4IM8"));
            siteRootAddress[3] = "&confirmationCode=";
            siteRootAddress[4] = Uri.EscapeDataString(user.EmailConfirmationCode);
            string        str1          = string.Concat(siteRootAddress);
            StringBuilder stringBuilder = new StringBuilder(this._emailTemplateProvider.GetDefaultTemplate());
            int           year          = DateTime.Now.Year;

            stringBuilder.Replace("{CURRENT_YEAR}", year.ToString());
            stringBuilder.Replace("{EMAIL_TITLE}", this.L("EmailActivation_Title"));
            stringBuilder.Replace("{EMAIL_SUB_TITLE}", this.L("EmailActivation_SubTitle"));
            StringBuilder stringBuilder1 = new StringBuilder();

            string[] strArrays = new string[] { "<b>", this.L("NameSurname"), "</b>: ", user.Name, " ", user.Surname, "<br />" };
            stringBuilder1.AppendLine(string.Concat(strArrays));
            if (!str.IsNullOrEmpty())
            {
                string[] strArrays1 = new string[] { "<b>", this.L("TenancyName"), "</b>: ", str, "<br />" };
                stringBuilder1.AppendLine(string.Concat(strArrays1));
            }
            string[] strArrays2 = new string[] { "<b>", this.L("UserName"), "</b>: ", user.UserName, "<br />" };
            stringBuilder1.AppendLine(string.Concat(strArrays2));
            if (!plainPassword.IsNullOrEmpty())
            {
                string[] strArrays3 = new string[] { "<b>", this.L("Password"), "</b>: ", plainPassword, "<br />" };
                stringBuilder1.AppendLine(string.Concat(strArrays3));
            }
            stringBuilder1.AppendLine("<br />");
            stringBuilder1.AppendLine(string.Concat(this.L("EmailActivation_ClickTheLinkBelowToVerifyYourEmail"), "<br /><br />"));
            string[] strArrays4 = new string[] { "<a href=\"", str1, "\">", str1, "</a>" };
            stringBuilder1.AppendLine(string.Concat(strArrays4));
            stringBuilder.Replace("{EMAIL_BODY}", stringBuilder1.ToString());
            await this._emailSender.SendAsync(user.EmailAddress, this.L("EmailActivation_Subject"), stringBuilder.ToString(), true);
        }
Example #3
0
        public void Should_Be_Able_To_Change_InitVector_And_Key()
        {
            const string initVectorString = "1234BCHF9876skd*";
            const string myKey            = "84ncpaKMC_!TuAna";
            const string plainText        = "This is a plain text!";

            var cipher = new SimpleStringCipher
            {
                InitVectorBytes = Encoding.ASCII.GetBytes(initVectorString)
            };

            var enryptedText = cipher.Encrypt(plainText, myKey);

            cipher.Decrypt(enryptedText, myKey).ShouldBe(plainText);
        }
Example #4
0
        /// <summary>
        /// Send email activation link to user's email address.
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="plainPassword">
        /// Can be set to user's plain password to include it in the email.
        /// </param>
        public async Task SendEmailActivationLinkAsync(User user, string plainPassword = null)
        {
            if (user.EmailConfirmationCode.IsNullOrEmpty())
            {
                throw new ApplicationException("EmailConfirmationCode should be set in order to send email activation link.");
            }

            var tenancyName = user.TenantId.HasValue
                ? _tenantRepository.Get(user.TenantId.Value).TenancyName
                : null;

            var link = _webUrlService.GetSiteRootAddress(tenancyName) + "Account/EmailConfirmation" +
                       "?userId=" + Uri.EscapeDataString(SimpleStringCipher.Encrypt(user.Id.ToString())) +
                       "&confirmationCode=" + Uri.EscapeDataString(user.EmailConfirmationCode);

            var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate());

            emailTemplate.Replace("{EMAIL_TITLE}", L("EmailActivation_Title"));
            emailTemplate.Replace("{EMAIL_SUB_TITLE}", L("EmailActivation_SubTitle"));

            var mailMessage = new StringBuilder();

            mailMessage.AppendLine("<b>" + L("NameSurname") + "</b>: " + user.Name + " " + user.Surname + "<br />");

            if (!tenancyName.IsNullOrEmpty())
            {
                mailMessage.AppendLine("<b>" + L("TenancyName") + "</b>: " + tenancyName + "<br />");
            }

            mailMessage.AppendLine("<b>" + L("UserName") + "</b>: " + user.UserName + "<br />");

            if (!plainPassword.IsNullOrEmpty())
            {
                mailMessage.AppendLine("<b>" + L("Password") + "</b>: " + plainPassword + "<br />");
            }

            mailMessage.AppendLine("<br />");
            mailMessage.AppendLine(L("EmailActivation_ClickTheLinkBelowToVerifyYourEmail") + "<br /><br />");
            mailMessage.AppendLine("<a href=\"" + link + "\">" + link + "</a>");

            emailTemplate.Replace("{EMAIL_BODY}", mailMessage.ToString());

            await _emailSender.SendAsync(user.EmailAddress, L("EmailActivation_Subject"), emailTemplate.ToString());
        }
Example #5
0
        private void button_autologin_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_username.Text) || (_cfg["Autologin"]["Enabled"] == "0" && string.IsNullOrEmpty(textBox_password.Text)))
            {
                if (string.IsNullOrEmpty(textBox_username.Text))
                {
                    textBox_username.Focus();
                }
                else
                {
                    textBox_password.Focus();
                }
                return;
            }

            _cfg["Autologin"]["Enabled"]  = "1";
            _cfg["Autologin"]["Username"] = textBox_username.Text;
            if (!string.IsNullOrEmpty(textBox_password.Text))
            {
                _cfg["Autologin"]["Password"] = SimpleStringCipher.Encrypt(textBox_password.Text, "OPENNOSROCKXXX");
            }

            int tmp = Convert.ToInt32(numericUpDown_delay.Value);

            if (tmp < 750)
            {
                tmp = 1000;
            }
            else if (tmp > 10000)
            {
                tmp = 10000;
            }
            _cfg["Autologin"]["Delay"] = tmp.ToString();

            _logInAs = textBox_username.Text;
            textBox_password.Text = "";
            button_back_Click(sender, null);
        }
Example #6
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);
        }