Esempio n. 1
0
        public void SeedManagerAccout()
        {
            ApplicationUserModel user1 = new ApplicationUserModel();
            user1.Id = Guid.NewGuid().ToString();
            user1.UserName = "******";
            user1.Password = "******";

            var userId = UserAccountManager.Create(user1);
            if (!String.IsNullOrWhiteSpace(userId))
            {
                AuthOption aa = new AuthOption();
                aa.AuthOption_Admin = true;

                using (ApplicationDbContext db=new ApplicationDbContext())
                {
                    var theUser = db.Users.FirstOrDefault(a => a.Id == userId);
                    UserAccountManager.InsertOrUpdateAuthOption(theUser, aa);
                }
            }

            EmployeeUserModel emp1 = new EmployeeUserModel();
            emp1.Id = Guid.NewGuid().ToString();
            emp1.UserName = "******";
            emp1.Password = "******";
            emp1.EmployeeProfile_Name = "M";

            var empId = UserAccountManager.CreateEmployee(emp1);
            if (!String.IsNullOrWhiteSpace(empId))
            {
                AuthOption aa = new AuthOption();
                aa.AuthOption_Admin = true;

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var theUser = db.Users.FirstOrDefault(a => a.Id == empId);
                    UserAccountManager.InsertOrUpdateAuthOption(theUser, aa);
                }
            }
        }
Esempio n. 2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUserModel user = new ApplicationUserModel();
                user.Id = Guid.NewGuid().ToString();
                user.UserName = model.UserName;
                user.Email = model.Email;
                user.Password = model.Password;

                var userId = UserAccountManager.Create(user);
                if (!String.IsNullOrWhiteSpace(userId))
                {
                    AuthOption aa = new AuthOption();
                    aa.AuthOption_Admin = true;

                    using (ApplicationDbContext db = new ApplicationDbContext())
                    {
                        var theUser = db.Users.FirstOrDefault(a => a.Id == userId);
                        UserAccountManager.InsertOrUpdateAuthOption(theUser, aa);
                    }
                }

                if (!String.IsNullOrEmpty(userId))
                {
                    var theUser = UserAccountManager.GetUserIdentityByName(user.UserName);
                    await SignInManager.SignInAsync(theUser, isPersistent: false, rememberBrowser: false);

                    // 如需如何啟用帳戶確認和密碼重設的詳細資訊,請造訪 http://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    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, "確認您的帳戶", "請按一下此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>");

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

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return View(model);
        }
Esempio n. 3
0
        public static void InsertOrUpdateAuthOption(ApplicationUser user, AuthOption authOption)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var userInDB = db.Users.FirstOrDefault(a => a.Id == user.Id);
                var authOptionInDB = db.AuthOptions.FirstOrDefault(a => a.AuthOption_Id == userInDB.IdFK_AuthOptions);

                // create
                if (authOptionInDB == null)
                {
                    userInDB.AuthOptions = authOption;
                    db.SaveChanges();
                    return;
                }

                authOptionInDB.AuthOption_Admin = authOption.AuthOption_Admin;
                //authOptionInDB.Taipei = authOption.Taipei;
                //authOptionInDB.Taoyuan = authOption.Taoyuan;
                //authOptionInDB.OrderTrucks = authOption.OrderTrucks;
                //authOptionInDB.OrderAirDoc = authOption.OrderAirDoc;
                //authOptionInDB.OrderInCityDoc = authOption.OrderInCityDoc;
                //authOptionInDB.Bills = authOption.Bills;
                //authOptionInDB.Drivers = authOption.Drivers;
                //authOptionInDB.Sales = authOption.Sales;
                //authOptionInDB.Customers = authOption.Customers;
                //authOptionInDB.PriceTemplate = authOption.PriceTemplate;
                //authOptionInDB.Employee = authOption.Employee;

                db.SaveChanges();
            }
        }