コード例 #1
0
 //פעולה המתרחשת כאשר המשתמש נכנס לדף
 protected void Page_Load(object sender, EventArgs e)
 {
     //בדיקה האם ישנו Query בכתובת הדף בשם code
     if (Request.QueryString["code"] != null)
     {
         // השמת ערך הquery במשתנה
         string code = Request.QueryString["code"];
         //בדיקה האם ישנו משתמש לא מופעל שלו שייך הקוד בquery
         if (ConfirmAccount.Activate(code))
         {
             status.Text = "המשתמש הופעל! כעת תועבר לעמוד כניסת משתמש רשום.";
             Response.AddHeader("REFRESH", "4;URL=Login.aspx");
         }
         //ניתוב המשתמש לדף כניסת משתמש אם הקוד אינו משוייך לאף משתמש שאינו פעיל
         else
         {
             Response.Redirect("Login.aspx");
         }
     }
     //ניתוב המשתמש לדף כניסת משתמש רשום אם הכתובת לא חוקית
     else
     {
         Response.Redirect("Login.aspx");
     }
 }
コード例 #2
0
        public async Task <IActionResult> ConfirmAccount(ConfirmAccount confirmAccount)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(confirmAccount.Email);

                if (user != null)
                {
                    var changePassword = await _userManager.ChangePasswordAsync(user, confirmAccount.CurrentPassword, confirmAccount.Password);

                    if (changePassword.Succeeded)
                    {
                        var CurrentUser = await _userManager.FindByEmailAsync(confirmAccount.Email);

                        CurrentUser.EmailConfirmed = true;
                        await _userManager.UpdateAsync(CurrentUser);

                        var result = await _signInManager.PasswordSignInAsync(confirmAccount.Email, confirmAccount.Password, true, lockoutOnFailure : false);

                        if (result.Succeeded)
                        {
                            _logger.LogInformation("User logged in.");
                            this.TempData["Mensaje"] = $"{Mensaje.MensajeSatisfactorio}|{"Bienvenido"}";
                            return(RedirectToAction(nameof(HomeController.Index), "Home"));
                        }
                    }
                    ModelState.AddModelError(string.Empty, "Intento de inicio de sesión no válido.");
                    return(View(confirmAccount));
                }
                ModelState.AddModelError(string.Empty, "Intento de inicio de sesión no válido.");
                return(View(confirmAccount));
            }
            ModelState.AddModelError(string.Empty, "Intento de inicio de sesión no válido.");
            return(View(confirmAccount));
        }
コード例 #3
0
        public void Handle(ConfirmAccount command)
        {
            var account = _repository.Find(command.AccountId);

            account.ConfirmAccount(command.ConfimationToken);
            _repository.Save(account, command.Id.ToString());
        }
コード例 #4
0
        public IHttpActionResult ConfirmEmail([FromBody] ConfirmAccount confirmAccount)
        {
            if (ModelState.IsValid)
            {
                string[] userData = Encoding.Unicode.GetString(Convert.FromBase64String(confirmAccount.ConfirmationData)).Split(new char[] { '#', '#' }, 2);

                if ((userData != null) && (userData[0] != null) && (userData[1] != null))
                {
                    User user = new User();
                    user.GetByUserName(userData[0]);
                    if (user.SecurityStamp == userData[1])
                    {
                        Dictionary <string, object> infoParameters = new Dictionary <string, object>();
                        infoParameters.Add("cUserName", userData[0]);
                        infoParameters.Add("SecurityStamp", userData[1]);
                        DataTable oUserData = DBConn.ExecuteCommand("sp_User_ConfirmLogin", infoParameters).Tables[0];

                        if (!oUserData.HasErrors)
                        {
                            return(Ok());
                        }
                    }
                }
            }

            return(BadRequest("Invalid confirmation data."));
        }
コード例 #5
0
        public async Task ConfirmAccountAsync(ConfirmAccount confirmAccount)
        {
            try
            {
                var confirmationResult = await _UserRepository
                                         .ConfirmationAccountAsync(confirmAccount.User, confirmAccount.ConfirmationToken);

                if (!confirmationResult)
                {
                    throw new AuthenticationException("Invalid token.");
                }
            }
            catch (Exception ex)
            {
                throw new AuthenticationException("Account confirmation failed.", ex);
            }
        }
コード例 #6
0
    protected string GenerateCode() //יצירת קוד אימות חדש
    {
        Random random     = new Random();
        string code       = "";
        string characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        for (int i = 0; i < 20; i++)
        {
            code += (characters[random.Next(characters.Length)]);
        }
        if (ConfirmAccount.CheckForCode(code))
        {
            return(GenerateCode());
        }
        else
        {
            return(code);
        }
    }
コード例 #7
0
    protected void SendRegistrationEmail(string address, string username) //שליחת הודעה למשתמש שנרשם עם פרטי בקשת לאישור המייל
    {
        string code    = GenerateCode();
        int    port    = HttpContext.Current.Request.Url.Port;
        string link    = "http://*****:*****@"
<html lang=""EN"">
<body style =""text-align:left; direction:rtl"">
<center>
<font color=""green"" size=""6"">
נרשמת לMarknet בהצלחה!
</font>
<br />
<font color=""black"" size=""3"">
שלום " + username + @", אנחנו שמחים להודיע לך שנרשמת לאתרנו בהצלחה! <br /> יש רק עוד שלב אחד, אנא לחץ <a href=""" + link + @""">כאן</a> כדי להפעיל את המשתמש שלך!
</center>
</body>
</html>";

        EmailService.SendEmail(address, "Marknet - אישור רישום משתמש", message); //שליחת המייל
        ConfirmAccount.AddCodeToAccount(username, code);                         //קישור בין קוד האימות למשתמש
    }