Пример #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new BakeryUser {
                    UserName = model.Email, Email = model.Email
                };
                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 https://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", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        public static void LogLogin(BakeryUser user)
        {
            LogUser loguser = new LogUser()
            {
                Id         = Guid.NewGuid().ToString(),
                bakeryuser = user,
                datetime   = DateTime.Now,
                logstring  = user.UserName + " Vừa Đăng nhập vào lúc" + DateTime.Now
            };

            Bakerycontext.logs.Add(loguser);
            Bakerycontext.SaveChanges();
        }
Пример #3
0
        public Rating check(Bakery bakery, BakeryUser user)
        {
            if (user == null)
            {
                return(null);
            }
            var check = db.rates.Where(p => p.bakery.ID == bakery.ID && p.User.Id == user.Id).SingleOrDefault();

            if (check == null)
            {
                return(null);
            }
            return(check);
        }
Пример #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var user = new BakeryUser {
                UserName = model.Email
            };
            IdentityResult result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                return(View());
            }
        }
Пример #5
0
        public void initialisedatabase()
        {
            var UserManager = new UserManager <BakeryUser>(new UserStore <BakeryUser>(bakerycontext));
            var RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(bakerycontext));

            var listoles = bakerycontext.Roles.ToList();

            if (!listoles.Any())
            {
                IdentityResult roleResult;

                if (!RoleManager.RoleExists(AdminRoles.Admin.ToString()))
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name  = AdminRoles.Admin.ToString();
                    roleResult = RoleManager.Create(role);
                }
                if (!RoleManager.RoleExists(AdminRoles.Editor.ToString()))
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name  = AdminRoles.Editor.ToString();
                    roleResult = RoleManager.Create(role);
                }
                if (!RoleManager.RoleExists(AdminRoles.User.ToString()))
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name  = AdminRoles.User.ToString();
                    roleResult = RoleManager.Create(role);
                }
            }
            var listuser = bakerycontext.Users.ToList();

            if (!listuser.Any())
            {
                var user = new BakeryUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";
                UserManager.Create(user, "123456");
                UserManager.AddToRole(user.Id, AdminRoles.Admin.ToString());
                var editoruser = new BakeryUser();
                editoruser.UserName = "******";
                editoruser.Email    = "*****@*****.**";
                UserManager.Create(editoruser, "123456");
                UserManager.AddToRole(editoruser.Id, AdminRoles.Editor.ToString());
            }
        }