public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { 
                    UserName = model.Email, 
                    Email = model.Email, 
                    FirstName = model.FirstName,
                    MiddleName = model.MiddleName,
                    LastName = model.LastName,
                    EGN = model.EGN,
                    PhoneNumber = model.Number
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                
                UserManager.AddToRole(user.Id, GlobalConstants.NOT_VERIFIED_USER);
           
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    
                    return RedirectToAction("NotVerified", "Validation");
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        private void GenerateAdmin(UserManager<User> userManager)
        {
            var passwordHash = new PasswordHasher();
            var user = new User()
            {
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = this.Generator.GenerateString(4, 10),
                MiddleName = this.Generator.GenerateString(4, 10),
                LastName = this.Generator.GenerateString(4, 10),
                EGN = this.Generator.GenerateNumber(10000000, 90000000),
                IsVerified = true,
                PhoneNumber = this.Generator.GenerateNumber(10000000, 90000000).ToString(),
                Teacher = new Teacher()
                {
                    Cabinet = this.Generator.GenerateNumber(1, 300),
                    OfficePhoneNumber = this.Generator.GenerateNumber(2000, 90000).ToString()
                },
                PasswordHash = passwordHash.HashPassword("*****@*****.**"),
                LockoutEnabled = true,
                SecurityStamp = Guid.NewGuid().ToString()
            };

            this.Context.Users.Add(user);
            this.Context.SaveChanges();

            userManager.AddToRole(user.Id, ADMIN);
            userManager.AddToRole(user.Id, TEACHER);
            userManager.AddToRole(user.Id, VERIFIED_USER);
            userManager.AddToRole(user.Id, COMPLETE_USER);
        }
 private async Task SignInUser(User user)
 {
     var signInManager = Request.GetOwinContext()
         .Get<ApplicationSignInManager>();
     await signInManager.SignInAsync(user, false, false);
 }
 private async Task SignInAsync(User user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
 }