protected void btnSavePassword_Click(object sender, System.EventArgs e) { Cuyahoga.Core.Domain.User currentUser = Context.User.Identity as Cuyahoga.Core.Domain.User; try { // Validate passwords if (!Cuyahoga.Core.Domain.User.ValidatePassword(this.txtNewPassword.Text) || !Cuyahoga.Core.Domain.User.ValidatePassword(this.txtCurrentPassword.Text)) { ShowError(GetText("INVALIDPASSWORD")); return; } // Check current password. if (currentUser.Password != Cuyahoga.Core.Domain.User.HashPassword(this.txtCurrentPassword.Text)) { ShowError(GetText("EDITPASSWORDCURRENTERROR")); return; } // Check if confirmation password is the same as the new password. if (this.txtNewPassword.Text != this.txtNewPasswordConfirmation.Text) { ShowError(GetText("EDITPASSWORDCONFIRMERROR")); return; } currentUser.Password = Cuyahoga.Core.Domain.User.HashPassword(this.txtNewPassword.Text); // Save user this._module.UpdateUser(currentUser); ShowMessage(GetText("EDITPASSWORDCONFIRMATION")); } catch (Exception ex) { ShowError(ex.Message); } }
public ActionResult Create(int[] roleIds) { User newUser = new User(); try { UpdateModel(newUser, new [] { "UserName", "FirstName", "LastName", "Email", "Website", "IsActive", "TimeZone" }); newUser.Password = CuyahogaUser.HashPassword(Request.Form["Password"]); newUser.PasswordConfirmation = CuyahogaUser.HashPassword(Request.Form["PasswordConfirmation"]); if (roleIds != null && roleIds.Length > 0) { IList <Role> roles = this._userService.GetRolesByIds(roleIds); foreach (Role role in roles) { newUser.Roles.Add(role); } } if (ValidateModel(newUser)) { this._userService.CreateUser(newUser); Messages.AddFlashMessageWithParams("UserCreatedMessage", newUser.UserName); return(RedirectToAction("Index")); } } catch (Exception ex) { Messages.AddException(ex); } ViewData["Roles"] = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite); ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", newUser.TimeZone); return(View("NewUser", newUser)); }
private bool AuthenticateUser(string username, string password, bool persistLogin) { try { CuyahogaUser user = this._authenticationService.AuthenticateUser(username, password, HttpContext.Current.Request.UserHostAddress); if (user != null) { if (!user.IsActive) { log.Warn(String.Format("Inactive user {0} tried to login.", user.UserName)); throw new AccessForbiddenException("The account is disabled."); } // Create the authentication ticket HttpContext.Current.User = user; FormsAuthentication.SetAuthCookie(user.Name, persistLogin); return(true); } else { log.Warn(String.Format("Invalid username-password combination: {0}:{1}.", username, password)); return(false); } } catch (Exception ex) { log.Error(String.Format("An error occured while logging in user {0}.", username)); throw new Exception(String.Format("Unable to log in user '{0}': " + ex.Message, username), ex); } }
public void TestBasketDao() { User user = new User(); IStoreContext context = new StoreContext(user); context.CurrencyCode = "GBP"; ECommerceModule module = CreateModule(); List<IProductSummary> l = (ServiceFactory.GetService(typeof(ICatalogueViewService)) as ICatalogueViewService).FindProducts(1, "en-GB", "o"); IBasketLine item1 = module.CommerceService.AddItem(context, l[0].ProductID, null, 3); IBasketLine item2 = module.CommerceService.AddItem(context, l[1].ProductID, null, 2); module.CommerceService.RefreshBasket(context); IBasket b = context.CurrentBasket; Assert.IsNotNull(b, "Null basket"); Assert.AreEqual(3, b.BasketItemList.Count); context.CurrentBasket = null; b = module.CommerceService.GetCurrentBasket(context); Assert.IsNotNull(b, "Not found"); Assert.IsTrue(b.BasketItemList.Count == 3); IBasketLine item3 = module.CommerceService.AddItem(context, l[0].ProductID, null, 3); module.CommerceService.RefreshBasket(context); Assert.AreEqual(3, b.BasketItemList.Count); module.CommerceService.RemoveItem(context, item1.BasketItemID); module.CommerceService.RefreshBasket(context); context.CurrentBasket = null; b = module.CommerceService.GetCurrentBasket(context); Assert.IsNotNull(b, "Not found"); Assert.AreEqual(2, b.BasketItemList.Count); decimal tax = b.TaxPrice.Amount; decimal expectedTax = b.SubTotal.Amount * 0.175M; Assert.IsTrue(tax <= expectedTax * 1.01M && tax >= expectedTax * 0.99M, "Tax is wrong"); OrderHeader header = new OrderHeader(); header.CreatedDate = DateTime.Now; header.Comment = "TEST"; header.PaymentMethod = Cuyahoga.Modules.ECommerce.Util.Enums.PaymentMethodType.CreditCard; header.PurchaseOrderNumber = StringUtils.GenerateRandomText(8); b.OrderHeader = header; module.CommerceService.RefreshBasket(context); b = module.CommerceService.GetCurrentBasket(context); Assert.IsNotNull(b.OrderHeader, "No header"); Assert.IsTrue(b.OrderHeader.OrderHeaderID > 0, "No header ID"); }
private void BindUser() { Cuyahoga.Core.Domain.User currentUser = Context.User.Identity as Cuyahoga.Core.Domain.User; this.lblUsername.Text = currentUser.UserName; this.txtFirstname.Text = currentUser.FirstName; this.txtLastname.Text = currentUser.LastName; this.txtEmail.Text = currentUser.Email; this.txtWebsite.Text = currentUser.Website; this.ddlTimeZone.Items.FindByValue(currentUser.TimeZone.ToString()).Selected = true; }
protected void Page_Load(object sender, EventArgs e) { CatalogueViewModule controller = Module as CatalogueViewModule; accountList = base.CoreRepository.GetAll((typeof(Cuyahoga.Core.Domain.User))); //(Cuyahoga.Core.Domain.User)base.CoreRepository.GetAll((typeof(Cuyahoga.Core.Domain.User))); repItemsPager.DataSource = accountList; repItemsPager.DataBind(); User u = new User(); }
public string CreateUser(string username, string email, Site currentSite) { User user = new User(); user.UserName = username; user.Email = email; user.IsActive = true; string newPassword = user.GeneratePassword(); // Add the default role from the current site. user.Roles.Add(currentSite.DefaultRole); this._commonDao.SaveOrUpdateObject(user); return newPassword; }
private void btnRegister_Click(object sender, System.EventArgs e) { if (this.Page.IsValid) { // Check if username already exists. if (_userService.FindUsersByUsername(this.txtUsername.Text).Count > 0) { this.lblError.Text = String.Format(GetTextFromFile("USEREXISTS"), this.txtUsername.Text); this.lblError.Visible = true; } else { Site site = this._page.ActiveNode.Site; // OK, create new user. User user = new User(); user.UserName = txtUsername.Text; user.Email = txtEmail.Text; user.IsActive = true; string newPassword = user.GeneratePassword(); // Add the default role from the current site. user.Roles.Add(site.DefaultRole); _userService.CreateUser(user); // Send email string subject = GetTextFromFile("REGISTEREMAILSUBJECT").Replace("{site}", site.Name); string body = GetTextFromFile("REGISTEREMAILBODY"); body = body.Replace("{site}", site.Name + " (" + site.SiteUrl + ")"); body = body.Replace("{username}", user.UserName); body = body.Replace("{password}", newPassword); try { Util.Email.Send(user.Email, site.WebmasterEmail, subject, body); this.pnlConfirmation.Visible = true; this.lblConfirmation.Text = String.Format(GetTextFromFile("REGISTERCONFIRMATION"), user.Email); } catch { // delete user when sending email fails. _userService.DeleteUser(user); this.lblError.Text = GetTextFromFile("REGISTEREMAILERROR"); this.lblError.Visible = true; } this.pnlRegister.Visible = false; } } }
private void BindUser(User user) { this.lblUsername.Text = user.UserName; this.lblFirstname.Text = user.FirstName; this.lblLastname.Text = user.LastName; if (user.Website != null && user.Website != string.Empty) { this.hplWebsite.NavigateUrl = user.Website; this.hplWebsite.Text = user.Website; } this.lblRegisteredOn.Text = user.InsertTimestamp.ToShortDateString(); if (user.LastLogin != null) { this.lblLastLogin.Text = user.LastLogin.ToString(); } }
public ActionResult ChangePassword(int id, string password, string passwordConfirmation) { User user = this._userService.GetUserById(id); try { user.Password = CuyahogaUser.HashPassword(password); user.PasswordConfirmation = CuyahogaUser.HashPassword(passwordConfirmation); if (ValidateModel(user, new[] { "Password", "PasswordConfirmation" })) { this._userService.UpdateUser(user); Messages.AddMessage("PasswordChangedMessage"); } } catch (Exception ex) { Messages.AddException(ex); } ViewData["Roles"] = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite); ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", user.TimeZone); return(View("EditUser", user)); }
protected void btnSave_Click(object sender, System.EventArgs e) { if (this.Page.IsValid) { Cuyahoga.Core.Domain.User currentUser = Context.User.Identity as Cuyahoga.Core.Domain.User; currentUser.FirstName = this.txtFirstname.Text; currentUser.LastName = this.txtLastname.Text; currentUser.Email = this.txtEmail.Text; currentUser.Website = this.txtWebsite.Text; currentUser.TimeZone = Int32.Parse(this.ddlTimeZone.SelectedValue); try { // Save user this._module.UpdateUser(currentUser); ShowMessage(GetText("EDITPROFILECONFIRMATION")); } catch (Exception ex) { ShowError(ex.Message); } } }
protected void Page_Load(object sender, EventArgs e) { this.lnkSave.Click += new EventHandler(lnkSave_Click); if (!IsPostBack) { try { AccountID = Int32.Parse(Request.Params[ACCOUNT_ID]); } catch { } CatalogueViewModule controller = Module as CatalogueViewModule; addressEditor.SetAvailableCountries(controller.AccountService.GetCountries()); userDetails = controller.AccountService.GetAccount(AccountID); AddressHelper.CopyAddress(userDetails.Address, addressEditor); u = (Cuyahoga.Core.Domain.User)base.CoreRepository.GetObjectById(typeof(Cuyahoga.Core.Domain.User), AccountID); userDetailsEditor.CultureCode = controller.Section.Node.Culture; userDetailsEditor.EmailAddress = u.Email; userDetailsEditor.FirstName = u.FirstName; userDetailsEditor.LastName = u.LastName; } }
public bool AllowModifyBasket(User user, IBasket basket) { return (basket != null && (basket.UserDetails == null || (user != null && basket.UserDetails.Id == user.Id))); }
public bool AllowPlaceOrder(User user) { return true; }
//should put this in account service. private void PerformRegistration() { try { UserDetail detail = new UserDetail(); UserDetailsHelper.CopyUserDetails(ctlUser, detail); Address Address = new Address(); AddressHelper.CopyAddress(ctlUserAddress, Address); EModule.CommonDao.SaveObject(Address); detail.Address = Address; EModule.CommonDao.SaveObject(detail); User user = new User(); user.Email = ctlUser.EmailAddress; user.UserName = ctlUser.EmailAddress; user.FirstName = ctlUser.FirstName; user.LastName = ctlUser.LastName; user.Password = User.HashPassword(ctlUser.Password); user.InsertTimestamp = DateTime.Now; user.IsActive = true; EModule.CommonDao.SaveObject(user); ctlUser.Visible = ctlUserAddress.Visible = false; } catch (Exception ex) { LogManager.GetLogger(GetType()).Debug(ex); DisplayErrorMessage(); } }
public bool Save() { CatalogueViewModule controller = Module as CatalogueViewModule; try { AccountID = Int32.Parse(Request.Params[ACCOUNT_ID]); } catch { } userDetails = controller.AccountService.GetAccount(AccountID); AddressHelper.CopyAddress(addressEditor, userDetails.Address); u = (Cuyahoga.Core.Domain.User)base.CoreRepository.GetObjectById(typeof(Cuyahoga.Core.Domain.User), AccountID); u.Email = userDetailsEditor.EmailAddress; u.FirstName = userDetailsEditor.FirstName; u.LastName = userDetailsEditor.LastName; if (controller.AccountService.SaveAccountDetails(userDetails)) { try { base.CoreRepository.UpdateObject(u); return true; } catch (Exception e) { LogManager.GetLogger(GetType()).Error(e); } } return false; }
public StoreContext(User user) { _user = user; }
public virtual bool IsViewAllowedForUser(User user) { return this.ViewRoles.Any(user.IsInRole); }
public bool AllowAddToBasket(User user) { return true; }
public bool ShowPrices(User user) { return true; }
public ActionResult New() { ViewData["Roles"] = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite); User user = new User(); ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", user.TimeZone); return View("NewUser", user); }
public void SaveOrUpdateUser(User user) { ISession session = this._sessionManager.OpenSession(); session.SaveOrUpdate(user); }
private void Page_Load(object sender, System.EventArgs e) { this.Title = "Edit user"; if (Context.Request.QueryString["UserId"] != null) { if (Int32.Parse(Context.Request.QueryString["UserId"]) == -1) { // Create a new user instance this._activeUser = new User(); } else { // Get user data this._activeUser = (Cuyahoga.Core.Domain.User)base.CoreRepository.GetObjectById(typeof(Cuyahoga.Core.Domain.User) , Int32.Parse(Context.Request.QueryString["UserId"])); } if (! this.IsPostBack) { BindTimeZones(); BindUserControls(); BindRoles(); } } }
public void UpdateUser(User user) { this._commonDao.SaveOrUpdateObject(user); }
/// <summary> /// Constructor. /// </summary> public SiteEdit() { this._currentUser = HttpContext.Current.User as User; }
private void btnAdmin_Click(object sender, EventArgs e) { if (this.IsValid) { // Only create an admin if there are really NO users. if (this._commonDao.GetAll(typeof(User)).Count > 0) { ShowError("There is already a user in the database. For security reasons Cuyahoga won't add a new user!"); } else { User newAdmin = new User(); newAdmin.UserName = "******"; newAdmin.Email = "*****@*****.**"; newAdmin.Password = Core.Domain.User.HashPassword(this.txtPassword.Text); newAdmin.IsActive = true; newAdmin.TimeZone = 0; try { Role adminRole = (Role)this._commonDao.GetObjectById(typeof(Role), 1); newAdmin.Roles.Add(adminRole); this._commonDao.SaveOrUpdateObject(newAdmin); this.pnlAdmin.Visible = false; this.pnlCreateSite.Visible = true; } catch (Exception ex) { ShowError("An error occured while creating the administrator: <br/>" + ex.ToString()); } } } }
public void BindUserDetails(User user) { UserDetails = new UserDecorator(user); UserDetailsAlt = null; }
public void DeleteUser(User user) { this._commonDao.DeleteObject(user); }
protected override void OnInit(EventArgs e) { if (this.Module.Section.CacheDuration > 0 && this.Module.CacheKey != null && !this.Page.User.Identity.IsAuthenticated && !this.Page.IsPostBack) { // Get the cached content. Don't use cached output after a postback. if (HttpContext.Current.Cache[this.Module.CacheKey] != null && !this.IsPostBack) { // Found cached content. this._cachedOutput = HttpContext.Current.Cache[this.Module.CacheKey].ToString(); } } if (this.Page is PageEngine) { this._pageEngine = (PageEngine)this.Page; } //custom for admin panel popup on site pages _cuyahogaUser = this.Page.User.Identity as User; if (this._cuyahogaUser != null && (this._cuyahogaUser.CanEdit(this._module.Section) || this._cuyahogaUser.IsInRole("Administrator")))//.HasPermission(AccessLevel.Administrator))) { //jQuery script for pop-up admin panel string adminjqpath = String.Format("{0}js/jquery-1.4.1.min.js", Cuyahoga.Web.Util.UrlHelper.GetApplicationPath().ToString()); this._pageEngine.RegisterJavascript("jquery", adminjqpath); string adminjspath = String.Format("{0}Admin/js/adminpanel.js", Cuyahoga.Web.Util.UrlHelper.GetApplicationPath().ToString()); this._pageEngine.RegisterJavascript("popadminjs", adminjspath); //CSS for popup panel string admincsspath = String.Format("{0}Admin/Css/adminpanel.css", Cuyahoga.Web.Util.UrlHelper.GetApplicationPath().ToString()); this._pageEngine.RegisterStylesheet("popadmincss", admincsspath); } base.OnInit(e); }
private void CheckAddItemRequest(User user, int quantity) { if (!_rules.AllowAddToBasket(user)) { throw new InvalidOperationException("Current user not allowed to add to basket"); } if (quantity < 1) { throw new ArgumentException("Invalid quantity"); } }
public IList<Section> GetViewableSectionsByUser(User user) { string hql = "select s from User u join u.Roles as r, Section s join s.SectionPermissions sp " + "where u.Id = :userId and r.Id = sp.Role.Id and sp.ViewAllowed = 1"; IQuery q = this._sessionManager.OpenSession().CreateQuery(hql); q.SetInt32("userId", user.Id); return q.List<Section>(); }
public StoreContext() { if (HttpContext.Current != null) { _user = HttpContext.Current.User as User; } }
public void DeleteUser(User user) { ISession session = this._sessionManager.OpenSession(); session.Delete(user); }
/// <summary> /// Set the Cuyahoga user for the current context. /// </summary> /// <param name="user"></param> public void SetUser(User user) { this._currentUser = user; HttpContext.Current.User = user; Thread.CurrentPrincipal = user; }
public ActionResult Create(int[] roleIds) { User newUser = new User(); try { UpdateModel(newUser, new []{ "UserName", "FirstName", "LastName", "Email", "Website", "IsActive", "TimeZone"}); newUser.Password = CuyahogaUser.HashPassword(Request.Form["Password"]); newUser.PasswordConfirmation = CuyahogaUser.HashPassword(Request.Form["PasswordConfirmation"]); if (roleIds != null && roleIds.Length > 0) { IList<Role> roles = this._userService.GetRolesByIds(roleIds); foreach (Role role in roles) { newUser.Roles.Add(role); } } if (ValidateModel(newUser)) { this._userService.CreateUser(newUser); Messages.AddFlashMessageWithParams("UserCreatedMessage", newUser.UserName); return RedirectToAction("Index"); } } catch (Exception ex) { Messages.AddException(ex); } ViewData["Roles"] = this._userService.GetAllRolesBySite(CuyahogaContext.CurrentSite); ViewData["TimeZones"] = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", newUser.TimeZone); return View("NewUser", newUser); }
public IUserDetails CreateUserDetails(User user) { UserDetail userDetails = new UserDetail(); userDetails.UserID = user.Id; return userDetails; }