diff --git a/WebControls/InputUserName.cs b/WebControls/InputUserName.cs new file mode 100644 index 00000000..83cd6c0a --- /dev/null +++ b/WebControls/InputUserName.cs @@ -0,0 +1,152 @@ +// +// SelectUserControl.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 Paul Schneider +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +using System; +using System.Web; +using System.Security.Permissions; +using System.Web.UI; +using System.Web.UI.WebControls; +using System.ComponentModel; +using System.Web.Security; + + +namespace Yavsc.WebControls +{ + /// + /// Select user control. + /// + [ + AspNetHostingPermission (SecurityAction.Demand, + Level = AspNetHostingPermissionLevel.Minimal), + AspNetHostingPermission (SecurityAction.InheritanceDemand, + Level = AspNetHostingPermissionLevel.Minimal), + ParseChildren (true), + DefaultProperty ("Name"), + ToolboxData ("<{0}:ResultPages runat=\"server\"> ") + ] + public class InputUserName: WebControl + { + /// + /// Initializes a new instance of the class. + /// + public InputUserName () + { + Multiple = false; + } + /// + /// Gets or sets the name. + /// + /// The name. + [Bindable (true)] + [DefaultValue("")] + [Localizable(true)] + public string Name { + get { + return (string) ViewState["Name"]; + } + set { + ViewState ["Name"] = value; + } + } + /// + /// Gets or sets the value. + /// + /// The value. + [Bindable (true)] + [DefaultValue("")] + [Localizable(true)] + public string Value { + get { + return (string) ViewState["Value"]; + } + set { + ViewState ["Value"] = value; + } + } + /// + /// Gets or sets the in role. + /// + /// The in role. + [Bindable (true)] + [DefaultValue("")] + [Localizable(true)] + public string InRole { + get { + return (string) ViewState["InRole"]; + } + set { + ViewState ["InRole"] = value; + } + } + + /// + /// Gets or sets a value indicating whether this is multiple. + /// + /// true if multiple; otherwise, false. + [Bindable (true)] + [DefaultValue(false)] + public bool Multiple { + get { + + return (bool) ViewState["Multiple"]; + } + set { + ViewState ["Multiple"] = value; + + } + } + + /// + /// Renders the contents. + /// + /// Writer. + protected override void RenderContents (HtmlTextWriter writer) + { + writer.AddAttribute ("id", ID); + writer.AddAttribute ("name", Name); + writer.AddAttribute ("class", CssClass); + if (Multiple) + writer.AddAttribute ("multiple","true"); + writer.RenderBeginTag ("select"); + string[] selected = null; + string[] roles = null; + if (!string.IsNullOrWhiteSpace (Value)) { + selected = Value.Split (','); + } + if (!string.IsNullOrWhiteSpace (InRole)) { + roles = InRole.Split (','); + } + foreach (MembershipUser u in Membership.GetAllUsers()) { + // if roles are specified, members must be in one of them + if (roles != null) + if (!Array.Exists (roles, x => Roles.IsUserInRole (x))) + continue; + if (selected!=null) + if (Array.Exists(selected, x=> x == u.UserName)) + writer.AddAttribute ("selected",null); + writer.RenderBeginTag ("option"); + writer.Write (u.UserName); + writer.RenderEndTag (); + } + writer.RenderEndTag (); + } + } +} + diff --git a/WebControls/ResultPages.cs b/WebControls/ResultPages.cs index 3943ed1b..bbf1d893 100644 --- a/WebControls/ResultPages.cs +++ b/WebControls/ResultPages.cs @@ -15,8 +15,8 @@ namespace Yavsc.WebControls Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), - ParseChildren (true, "Action"), - DefaultProperty ("Action"), + ParseChildren (true), + ToolboxData ("<{0}:ResultPages runat=\"server\"> ") ] public class ResultPages: WebControl @@ -24,7 +24,7 @@ namespace Yavsc.WebControls /// /// Initializes a new instance of the class. /// - public ResultPages () + public ResultPages () { } diff --git a/WebControls/WebControls.csproj b/WebControls/WebControls.csproj index d8b93c1d..2405ce2f 100644 --- a/WebControls/WebControls.csproj +++ b/WebControls/WebControls.csproj @@ -38,10 +38,12 @@ + + \ No newline at end of file diff --git a/web/ApiControllers/WorkFlowController.cs b/web/ApiControllers/WorkFlowController.cs index a2cd1fc0..285849a3 100644 --- a/web/ApiControllers/WorkFlowController.cs +++ b/web/ApiControllers/WorkFlowController.cs @@ -9,6 +9,9 @@ using Yavsc.Model.WorkFlow; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.ModelBinding; +using Yavsc.Model.RolesAndMembers; +using Yavsc.Helpers; +using Yavsc.Model; namespace Yavsc.ApiControllers { @@ -51,6 +54,45 @@ namespace Yavsc.ApiControllers Membership.GetUser().UserName,client,title,description); } + /// + /// Register the specified model and isapprouved. + /// + /// Model. + /// If set to true isapprouved. + [HttpGet] + [ValidateAjax] + [Authorize(Roles="Admin,FrontOffice")] + public void Register([FromBody] RegisterModel model) + { + if (ModelState.IsValid) { + MembershipCreateStatus mcs; + var user = Membership.CreateUser ( + model.UserName, + model.Password, + model.Email, + null, + null, + model.IsApprouved, + out mcs); + switch (mcs) { + case MembershipCreateStatus.DuplicateEmail: + ModelState.AddModelError ("Email", + string.Format(LocalizedText.DuplicateEmail,model.UserName) ); + return ; + case MembershipCreateStatus.DuplicateUserName: + ModelState.AddModelError ("UserName", + string.Format(LocalizedText.DuplicateUserName,model.Email)); + return ; + case MembershipCreateStatus.Success: + if (!model.IsApprouved) + YavscHelpers.SendActivationEmail (user); + return; + default: + throw new InvalidOperationException (string.Format("Unexpected user creation code :{0}",mcs)); + } + } + } + /// /// Drops the writting. /// diff --git a/web/IValueProvider.cs b/web/IValueProvider.cs index 99a58d8d..329b0bd0 100644 --- a/web/IValueProvider.cs +++ b/web/IValueProvider.cs @@ -1,5 +1,4 @@ using System; -using Yavsc; using SalesCatalog; using System.Web.Routing; using System.Threading.Tasks; diff --git a/web/TemplateException.cs b/web/TemplateException.cs index 61152d43..fcb18344 100644 --- a/web/TemplateException.cs +++ b/web/TemplateException.cs @@ -1,5 +1,4 @@ using System; -using Yavsc; using SalesCatalog; using System.Web.Routing; using System.Threading.Tasks; diff --git a/web/Views/FrontOffice/Estimate.aspx b/web/Views/FrontOffice/Estimate.aspx index 729e5f68..27d52e3c 100644 --- a/web/Views/FrontOffice/Estimate.aspx +++ b/web/Views/FrontOffice/Estimate.aspx @@ -1,4 +1,5 @@ <%@ Page Title="Devis" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %> +<%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %> @@ -18,7 +19,12 @@ $("#tbwrts").stupidtable(); <%= Html.ValidationMessage("Title", "*") %>
<%= Html.Hidden ("Responsible") %> -<%= Html.LabelFor(model => model.Client) %>:<%=Html.TextBox( "Client" ) %> + +<%= Html.LabelFor(model => model.Client) %>: + <% Client.Value = Model.Client ; %> + + + <%= Html.ValidationMessage("Client", "*") %>
<%= Html.LabelFor(model => model.Description) %>:<%=Html.TextArea( "Description") %> diff --git a/yavscModel/LocalizedText.Designer.cs b/yavscModel/LocalizedText.Designer.cs index 95e1904a..5982ea96 100644 --- a/yavscModel/LocalizedText.Designer.cs +++ b/yavscModel/LocalizedText.Designer.cs @@ -178,6 +178,12 @@ namespace Yavsc.Model { } } + public static string DuplicateUserName { + get { + return ResourceManager.GetString("DuplicateUserName", resourceCulture); + } + } + public static string Tex_version { get { return ResourceManager.GetString("Tex_version", resourceCulture); @@ -208,6 +214,12 @@ namespace Yavsc.Model { } } + public static string DuplicateEmail { + get { + return ResourceManager.GetString("DuplicateEmail", resourceCulture); + } + } + public static string Product_reference { get { return ResourceManager.GetString("Product_reference", resourceCulture); diff --git a/yavscModel/LocalizedText.resx b/yavscModel/LocalizedText.resx index 52cd3306..ede55f56 100644 --- a/yavscModel/LocalizedText.resx +++ b/yavscModel/LocalizedText.resx @@ -47,4 +47,6 @@ role created Item added to basket Estimate not found + This email adress is already used ({0}). + This user name is already used ({0}). diff --git a/yavscModel/RolesAndMemebers/RegisterModel.cs b/yavscModel/RolesAndMemebers/RegisterModel.cs index 02d0fb47..794e6ae0 100644 --- a/yavscModel/RolesAndMemebers/RegisterModel.cs +++ b/yavscModel/RolesAndMemebers/RegisterModel.cs @@ -25,6 +25,7 @@ using System.ComponentModel.DataAnnotations; namespace Yavsc.Model.RolesAndMembers { + /// /// Register view model. /// @@ -53,6 +54,13 @@ namespace Yavsc.Model.RolesAndMembers [DisplayName("Adresse e-mail")] [Required(ErrorMessage = "S'il vous plait, entrez un e-mail valide")] public string Email { get; set; } + + public bool IsApprouved { get; set; } + + public RegisterModel() + { + IsApprouved = false; + } } }