private void PublishToEventBus(UserDetails user)
        {
            //Do your preparation (e.g. Start code) here
            var queueName = settings.EventBusQueue;

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(
                        queue: settings.EventBusQueue,
                        durable: false,
                        exclusive: false,
                        autoDelete: false,
                        arguments: null);

                    var userDetails = new NewUserDetails
                    {
                        Id        = user.Id,
                        FirstName = user.FirstName,
                        LastName  = user.LastName,
                        LoginUrl  = settings.LoginUrl
                    };

                    var message = JsonConvert.SerializeObject(userDetails);
                    var body    = Encoding.UTF8.GetBytes(message);

                    channel.BasicPublish(
                        exchange: "",
                        routingKey: settings.EventBusQueue,
                        basicProperties: null,
                        body: body);
                }
        }
        public void FillDetails()
        {
            NewUserDetails u = new NewUserDetails();

            u.FirstName    = "Random";
            u.LastName     = "Person";
            u.UserName     = "******" + DateTime.Now.Millisecond;
            u.CurrentEmail = "*****@*****.**";
            u.Password     = "******";
            u.BirthMonth   = 1;
            u.BirthDate    = "01";
            u.BirthYear    = "1980";
            u.Phone        = "+1-432-132-4552";


            DOM.Find("#FirstName").SendKeys(u.FirstName);
            DOM.Find("#LastName").SendKeys(u.LastName);
            DOM.Find("#GmailAddress").SendKeys(u.UserName);
            DOM.Find("#Passwd").SendKeys(u.Password);
            DOM.Find("#PasswdAgain").SendKeys(u.Password);
            DOM.Find("#BirthMonth").SendKeys(u.BirthMonth.ToString());
            DOM.Find("#BirthDay").SendKeys(u.BirthDate);
            DOM.Find("#BirthYear").SendKeys(u.BirthYear);
            DOM.Find("#RecoveryEmailAddress").SendKeys(u.CurrentEmail);
            DOM.Find("#submitbutton").Click();
        }
 private bool IsPasswordMatching(NewUserDetails newUser)
 {
     if (newUser.Password == newUser.PasswordRepeate)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public async Task <IActionResult> Login(NewUserDetails user)
        {
            //Kontrollerar inloggningen mot databasen
            var result = await _signinmanager.PasswordSignInAsync(user.Name, user.Password, false, true);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "Felaktig inloggning";
                return(View());
            }
        }
        public async Task <IActionResult> Register(NewUserDetails newUser)
        {
            if (!IsPasswordMatching(newUser))
            {
                ViewBag.Message = "Password does not match";
                return(View());
            }

            ApplicationUser newAccount = new ApplicationUser()
            {
                UserName    = newUser.Username,
                Email       = newUser.Email,
                Namn        = newUser.Name,
                PhoneNumber = newUser.PhoneNumber,
                Postnr      = newUser.Zipcode,
                Gatuadress  = newUser.StreetAddress,
                Postort     = newUser.Region
            };



            // Creates and adds new user to the db. Pw Will be controlled to meet all requirements.
            var result = await _usermanager.CreateAsync(newAccount, newUser.Password);

            //Koppla användaren till en roll
            await _usermanager.AddToRoleAsync(newAccount, newUser.RoleName);



            if (result.Succeeded)
            {
                await _signinmanager.SignInAsync(newAccount, isPersistent : true);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "Information given is not correct. Please try again";
                return(View());
            }
        }