Пример #1
0
        //[RequireHttps]
        //[RefererHeader]
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            CheckAda();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, ADA = model.ADA
                };
                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>");

                    QueueConnector.createQueue(parseUserName(user.UserName));

                    QueueManager.SendImageEntityToQueueforuserAccount(parseUserName(user.UserName), DateTime.Now);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        protected void Seed(ApplicationDbContext db)
        {
            RoleStore <IdentityRole>    roleStore = new RoleStore <IdentityRole>(db);
            UserStore <ApplicationUser> userStore = new UserStore <ApplicationUser>(db);

            RoleManager <IdentityRole>    rm = new RoleManager <IdentityRole>(roleStore);
            UserManager <ApplicationUser> um = new UserManager <ApplicationUser>(userStore);

            IdentityResult ir;

            ApplicationUser nobody = createUser("*****@*****.**");
            ApplicationUser jfk    = createUser("*****@*****.**");
            ApplicationUser nixon  = createUser("*****@*****.**");
            ApplicationUser fdr    = createUser("*****@*****.**");

            ir = um.Create(nobody, "nobody1234");

            ir = um.Create(jfk, "jfk1234");

            ir = um.Create(nixon, "nixon1234");

            ir = um.Create(fdr, "fdr1234");


            rm.Create(new IdentityRole("User"));
            rm.Create(new IdentityRole("Supervisor"));

            if (!um.IsInRole(nobody.Id, "User"))
            {
                um.AddToRole(nobody.Id, "User");
            }
            if (!um.IsInRole(jfk.Id, "User"))
            {
                um.AddToRole(jfk.Id, "User");
            }
            if (!um.IsInRole(nixon.Id, "User"))
            {
                um.AddToRole(nixon.Id, "User");
            }

            if (!um.IsInRole(fdr.Id, "User"))
            {
                um.AddToRole(fdr.Id, "User");
            }

            rm.Create(new IdentityRole("Admin"));
            if (!um.IsInRole(nixon.Id, "Admin"))
            {
                um.AddToRole(nixon.Id, "Admin");
            }

            rm.Create(new IdentityRole("Approver"));
            if (!um.IsInRole(jfk.Id, "Approver"))
            {
                um.AddToRole(jfk.Id, "Approver");
            }

            rm.Create(new IdentityRole("Supervisor"));
            if (!um.IsInRole(fdr.Id, "Supervisor"))
            {
                um.AddToRole(fdr.Id, "Supervisor");
            }

            db.Tags.Add(new Tag {
                Name = "portrait"
            });
            db.Tags.Add(new Tag {
                Name = "architecture"
            });


            db.SaveChanges();



            db.Images.Add(new Image
            {
                Caption     = "jelly fish",
                Description = "lives in sea and ocean",
                DateTaken   = new DateTime(1946, 12, 14),
                //  UserId = jfk.Id,
                UserId    = jfk.Id,
                TagId     = 1,
                Validated = true,
                Approved  = true
            });
            LogContext.CreateTable();
            db.SaveChanges();

            QueueConnector.createQueue(parseUserName(jfk.UserName));
            QueueConnector.createQueue(parseUserName(nobody.UserName));
            QueueConnector.createQueue(parseUserName(nixon.UserName));
            QueueConnector.createQueue(parseUserName(fdr.UserName));

            //base.Seed(db);



            //     base.Seed(db);
        }