Beispiel #1
0
        public IActionResult Register(AccountRegister new_user)
        {
            using (GlobalDBContext _context = new GlobalDBContext())
            {
                string _domainurl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";
                // ->TODO Validation check on clinet side using Jquery or JavaScript

                // Password hashed with extra layer of security
                string password          = new_user.Password;
                CustomPasswordHasher pwd = new CustomPasswordHasher();
                // increse the size to increase secuirty but lower performance
                string salt   = pwd.CreateSalt(10);
                string hashed = pwd.HashPassword(password, salt);
                //new_user.Salt = salt;
                new_user.Password = hashed;
                // var errors = ModelState.Values.SelectMany(v => v.Errors);
                Role role    = _context.Roles.Find(new_user.UserRole);
                User theUser = new User();
                theUser.AddFromAccountRegsiter(new_user, role, salt);
                string uniqueToken = Guid.NewGuid().ToString("N").Substring(0, 6);
                theUser.UniqueToken = uniqueToken;
                _context.Users.Add(theUser);

                SendEmail email    = new SendEmail(_emailSettings);
                string    fullname = theUser.UserFirstName + " " + theUser.UserLastName;
                string    msg      = "Please verify you email account for the verification. Click on the link to verify :";
                msg += _domainurl + "/Account/ConfirmEmail?email=" + theUser.UserEmail + "&token=" + theUser.UniqueToken;

                _context.SaveChanges();
                email.SendEmailtoUser(fullname, theUser.UserEmail, "Email Verification", msg);
                ViewBag.Messsage = new_user.FirstName + " " + new_user.LastName + " successfully registered. A Email has been sent for the verfication.";
            }
            return(View());
        }