private static void InitCustomers(AppContext context) { var customer = new Customer() { UserName = "******", Email = "*****@*****.**", Password = "******", FirstName = "unigo", LastName = "unigo", Active = true, Deleted = false, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow }; if (context.Set<Customer>().Any()) return; var customrole = context.Set<CustomerRole>().FirstOrDefault(x => x.SystemName == "Admin"); customer.CustomerRoles.Add(customrole); context.Set<Customer>().AddOrUpdate(customer); context.SaveChanges(); }
/// <summary> /// Authorize permission /// </summary> /// <param name="permission">Permission record</param> /// <param name="customer">Customer</param> /// <returns>true - authorized; otherwise, false</returns> public virtual bool Authorize(PermissionRecord permission, Customer customer) { if (permission == null) return false; if (customer == null) return false; return Authorize(permission.SystemName, customer); }
public Customer GetAuthenticatedCustomer() { if (_cachedCustomer != null) return _cachedCustomer; if (_httpContext == null || _httpContext.Request == null || !_httpContext.Request.IsAuthenticated || !(_httpContext.User.Identity is FormsIdentity)) { return null; } //var userName = _httpContext.User.Identity.Name; //var user = _userService.GetUserByEmail(userName); var customerId = _httpContext.User.Identity.Name; var customer = _customerService.GetById(Convert.ToInt32(customerId)); if (customer != null && customer.Active && !customer.Deleted) _cachedCustomer = customer; return _cachedCustomer; }
public void Login(Customer customer, bool persistentCookie) { FormsAuthentication.SetAuthCookie(customer.Id.ToString(), persistentCookie); }
/// <summary> /// Gets a customer time zone /// </summary> /// <param name="customer">Customer</param> /// <returns>Customer time zone; if customer is null, then default store time zone</returns> public virtual TimeZoneInfo GetCustomerTimeZone(Customer customer) { //registered user TimeZoneInfo timeZoneInfo = null; //if (_dateTimeSettings.AllowCustomersToSetTimeZone) { string timeZoneId = string.Empty; if (customer != null) timeZoneId = customer.TimeZoneId; try { if (!String.IsNullOrEmpty(timeZoneId)) timeZoneInfo = FindTimeZoneById(timeZoneId); } catch (Exception exc) { Debug.Write(exc.ToString()); } } //default timezone if (timeZoneInfo == null) timeZoneInfo = this.DefaultStoreTimeZone; return timeZoneInfo; }
/// <summary> /// Authorize permission /// </summary> /// <param name="permissionRecordSystemName">Permission record system name</param> /// <param name="customer">Customer</param> /// <returns>true - authorized; otherwise, false</returns> public virtual bool Authorize(string permissionRecordSystemName, Customer customer) { if (String.IsNullOrEmpty(permissionRecordSystemName)) return false; var customerRoles = customer.CustomerRoles.Where(cr => cr.Active); foreach (var role in customerRoles) if (Authorize(permissionRecordSystemName, role)) //yes, we have such permission return true; //no permission found return false; }
protected Customer GetCurrentCustomer() { if (_cachedCustomer != null) return _cachedCustomer; if (!IsAuthenticated) return null; Customer customer = null; if (_httpContext != null) { customer = _authenticationService.GetAuthenticatedCustomer(); } //validation if (customer != null && !customer.Deleted && customer.Active) { //update last activity date if (customer.LastActivityDateUtc.AddMinutes(1.0) < DateTime.UtcNow) { customer.LastActivityDateUtc = DateTime.UtcNow; _customerService.Update(customer); } //update IP address string currentIpAddress = _webHelper.GetCurrentIpAddress(); if (!String.IsNullOrEmpty(currentIpAddress)) { if (!currentIpAddress.Equals(customer.LastIpAddress)) { customer.LastIpAddress = currentIpAddress; _customerService.Update(customer); } } _cachedCustomer = customer; } return _cachedCustomer; }