コード例 #1
0
        public ActionResult SignIn(string email, string password)
        {
            if (user != null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var context = new SpectroContext();

            ViewBag.email    = email;
            ViewBag.password = password;

            password = Crypto.SHA256(password).ToLower();

            Account account = context.Accounts.First(a => a.Email == email);

            if (account.Password == password)
            {
                FormsAuthentication.SetAuthCookie(account.Email, createPersistentCookie: true);
                Session["Account"] = account;

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.error = "Invalid email / password combination";
            }

            return(View());
        }
コード例 #2
0
        protected override void Seed(SpectroContext context)
        {
            Account[] accounts = new Account[] {
                new Account()
                {
                    ID = 1, Name = "Jane Austen", Email = "*****@*****.**", Password = "******"
                },
                new Account()
                {
                    ID = 2, Name = "Charles Dickens", Email = "*****@*****.**", Password = "******"
                },
                new Account()
                {
                    ID = 3, Name = "Miguel de Cervantes", Email = "*****@*****.**", Password = "******"
                }
            };

            context.Accounts.AddOrUpdate(
                x => x.ID, accounts
                );

            context.Posts.AddOrUpdate(
                x => x.ID,
                new Post()
            {
                ID        = 1,
                IsPublic  = true,
                Title     = "Did Microsoft just give up on Windows Phone?",
                Content   = "",
                CreatedAt = DateTime.Now,
                Account   = accounts[0]
            },
                new Post()
            {
                ID        = 2,
                IsPublic  = true,
                Title     = "Han Solo's spinoff film will let Disney keep the original Star Wars trilogy alive",
                Content   = "",
                CreatedAt = DateTime.Now,
                Account   = accounts[1]
            },
                new Post()
            {
                ID        = 3,
                IsPublic  = true,
                Title     = "Alexa, tell me what it's like to use the Amazon Echo",
                Content   = "",
                CreatedAt = DateTime.Now,
                Account   = accounts[2]
            }
                );
        }
コード例 #3
0
 public _BaseController()
 {
     this.context = new SpectroContext();
 }