Example #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new SPMUser {
                    UserName = model.Email.ToLower(), Email = model.Email.ToLower()
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                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("Index", "DefaultCharts"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #2
0
        public void ConvertUsers()
        {
            Console.WriteLine("Starting User converison.");
            var roleStore   = new RoleStore <IdentityRole>(db);
            var roleManager = new RoleManager <IdentityRole>(roleStore);
            var userStore   = new UserStore <SPMUser>(db);
            var userManager = new UserManager <SPMUser>(userStore);



            foreach (var row in OldUsersTable)
            {
                var user = new SPMUser {
                    UserName = row.Email.ToLower(), Email = row.Email.ToLower()
                };
                userManager.Create(user, "!a2b3c4d5e6G");
                user.ReceiveAlerts = false;
                try
                {
                    userManager.AddToRole(user.Id, "User");
                }
                catch
                {
                    Console.WriteLine("Unable to add user " + row.Name + "to the database.");
                }
            }
            Console.WriteLine("Saving Users");
            db.SaveChanges();
        }
Example #3
0
        public ActionResult DeleteConfirmed(string id)
        {
            SPMUser sPMUser = db.Users.Find(id);

            db.Users.Remove(sPMUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
 public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] SPMUser sPMUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sPMUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sPMUser));
 }
Example #5
0
        // GET: SPMUsers/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SPMUser sPMUser = db.Users.Find(id);

            if (sPMUser == null)
            {
                return(HttpNotFound());
            }
            return(View(sPMUser));
        }
Example #6
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }
            if (returnUrl == null)
            {
                returnUrl = "~/DefaultCharts/Index";
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new SPMUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }