コード例 #1
0
ファイル: CustomPrincipal.cs プロジェクト: nhtera/CrowdCMS
 public CustomPrincipal(CustomPrincipalSerializeModel adminUser, int? groupID, List<string> permissions, bool authenticated)
 {
     UserID = adminUser.UserID;
     UserName = adminUser.UserName;
     IsAdmn = adminUser.IsAdmn;
     UserGroupID = groupID;
     Email = adminUser.Email;
     Identity = new CustomIdentity(adminUser.UserName, authenticated);
     Permissions = permissions;
 }
コード例 #2
0
 public CustomPrincipal(CustomPrincipalSerializeModel adminUser, int?groupID, List <string> permissions, bool authenticated)
 {
     UserID      = adminUser.UserID;
     UserName    = adminUser.UserName;
     IsAdmn      = adminUser.IsAdmn;
     UserGroupID = groupID;
     Email       = adminUser.Email;
     Identity    = new CustomIdentity(adminUser.UserName, authenticated);
     Permissions = permissions;
 }
コード例 #3
0
ファイル: AdmnController.cs プロジェクト: nhtera/CrowdCMS
        public ActionResult Login(LoginModel loginModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var admin = UserService.GetUserByEmailAndPassword(loginModel.Email, loginModel.Password);
                if (admin != null)
                {
                    var principal = new CustomPrincipalSerializeModel()
                    {
                        Email = admin.US_Email,
                        UserID = admin.AdminUserID,
                        UserName = admin.US_UserName,
                        IsAdmn = true
                    };
                    var principalString = new JavaScriptSerializer().Serialize(principal);

                    var authTicket = new FormsAuthenticationTicket(1, admin.US_UserName, DateTime.Now, DateTime.Now.AddDays(SettingsManager.CookieExpireTime), true, principalString, FormsAuthentication.FormsCookiePath);
                    var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    Response.Cookies.Add(cookie);

                    if (String.IsNullOrEmpty(returnUrl))
                        return RedirectToAction("Home", "Admn");
                    return Redirect(returnUrl);
                }
                else
                    ModelState.AddModelError("", "Email or Password is not valid.");
            }
            return View();
        }
コード例 #4
0
ファイル: WebsiteController.cs プロジェクト: nhtera/CrowdCMS
        public ActionResult Registration(RegistrationModel model, string returnUrl)
        {
            this.ViewBag.Countries = ECommerceService.GetAllCountriesAsSelectList(this.DomainID);

            if (ModelState.IsValid)
            {
                var customer = UserService.GetCustomerByEmail(model.Email, DomainID);
                if (customer != null)
                {
                    ModelState.AddModelError("", "This email is already registered in our database.");
                    return View();
                }

                customer = UserService.SaveCustomer(model.Email, model.FirstName, model.Surname, String.Empty, String.Empty, model.Password, DomainID, 0, true, model.DetailsFor3rdParties, "");
                if (customer != null)
                {
                    ECommerceService.SaveAddress(customer.CustomerID, model.CountryID, model.County, model.FirstName, model.Surname, String.Empty,
                        model.Address1, model.Address2, model.Address3, model.Postcode, String.Empty, model.Town, 0);

                    var principal = new CustomPrincipalSerializeModel();
                    principal.Email = customer.CU_Email;
                    principal.UserID = customer.CustomerID;
                    principal.UserName = String.Format("{0} {1}", customer.CU_FirstName, customer.CU_Surname);
                    principal.IsAdmn = false;
                    var principalString = JsonConvert.SerializeObject(principal);

                    var authTicket = new FormsAuthenticationTicket(1, customer.CU_Email, DateTime.Now, DateTime.Now.AddDays(SettingsManager.CookieExpireTime), true, principalString, FormsAuthentication.FormsCookiePath);
                    var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    Response.Cookies.Add(cookie);

                    if (this.Domain.IsAnyCRMEnabled)
                        UserService.SubscribeNewsletter(customer.CU_Email, model.Newsletter, this.DomainID);

                    MailingService.SendWelcomeMessage(principal.UserName, model.Email, this.Domain.DO_CompanyName, this.Domain.DO_Domain, this.Domain.DO_CompanyTelephone);
                }
                else
                    ModelState.AddModelError("", "There was an error saving new customer.");

                if (String.IsNullOrEmpty(returnUrl))
                    return RedirectToRoute("RegisterConfirmation");
                return Redirect(returnUrl);
            }
            return View();
        }
コード例 #5
0
ファイル: WebsiteController.cs プロジェクト: nhtera/CrowdCMS
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var customer = UserService.GetCustomerByEmailAndPassword(model.Email, model.Password, DomainID);
                if (customer != null)
                {
                    var principal = new CustomPrincipalSerializeModel();
                    principal.Email = customer.CU_Email;
                    principal.UserID = customer.CustomerID;
                    principal.UserName = String.Format("{0} {1}", customer.CU_FirstName, customer.CU_Surname);
                    principal.IsAdmn = false;
                    var principalString = JsonConvert.SerializeObject(principal);

                    var authTicket = new FormsAuthenticationTicket(1, customer.CU_Email, DateTime.Now, DateTime.Now.AddDays(SettingsManager.CookieExpireTime), true, principalString, FormsAuthentication.FormsCookiePath);
                    var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    Response.Cookies.Add(cookie);

                    if (String.IsNullOrEmpty(returnUrl))
                        return RedirectToAction("Content");
                    return Redirect(returnUrl);
                }
                else
                    ModelState.AddModelError("", "Email or Password is not valid.");
            }
            return View();
        }