* InputUserName.cs:

* WebControls.csproj:
* Estimate.aspx: UserName input control

* IValueProvider.cs:
* TemplateException.cs:
* ResultPages.cs: code cleanning

* WorkFlowController.cs: Admin now can register new users

* LocalizedText.resx:
* LocalizedText.Designer.cs: new registration messages

* RegisterModel.cs: The registration message contains the user
  validation decision
vnext
Paul Schneider 10 years ago
parent c943606b43
commit cce43b9daf
10 changed files with 228 additions and 6 deletions

@ -0,0 +1,152 @@
//
// SelectUserControl.cs
//
// Author:
// Paul Schneider <paulschneider@free.fr>
//
// 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 <http://www.gnu.org/licenses/>.
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
{
/// <summary>
/// Select user control.
/// </summary>
[
AspNetHostingPermission (SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission (SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
ParseChildren (true),
DefaultProperty ("Name"),
ToolboxData ("<{0}:ResultPages runat=\"server\"> </{0}:ResultPages>")
]
public class InputUserName: WebControl
{
/// <summary>
/// Initializes a new instance of the <see cref="WebControls.InputUserName"/> class.
/// </summary>
public InputUserName ()
{
Multiple = false;
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[Bindable (true)]
[DefaultValue("")]
[Localizable(true)]
public string Name {
get {
return (string) ViewState["Name"];
}
set {
ViewState ["Name"] = value;
}
}
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
[Bindable (true)]
[DefaultValue("")]
[Localizable(true)]
public string Value {
get {
return (string) ViewState["Value"];
}
set {
ViewState ["Value"] = value;
}
}
/// <summary>
/// Gets or sets the in role.
/// </summary>
/// <value>The in role.</value>
[Bindable (true)]
[DefaultValue("")]
[Localizable(true)]
public string InRole {
get {
return (string) ViewState["InRole"];
}
set {
ViewState ["InRole"] = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Yavsc.WebControls.InputUserName"/> is multiple.
/// </summary>
/// <value><c>true</c> if multiple; otherwise, <c>false</c>.</value>
[Bindable (true)]
[DefaultValue(false)]
public bool Multiple {
get {
return (bool) ViewState["Multiple"];
}
set {
ViewState ["Multiple"] = value;
}
}
/// <summary>
/// Renders the contents.
/// </summary>
/// <param name="writer">Writer.</param>
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 ();
}
}
}

@ -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\"> </{0}:ResultPages>")
]
public class ResultPages: WebControl
@ -24,7 +24,7 @@ namespace Yavsc.WebControls
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.WebControls.ResultPages"/> class.
/// </summary>
public ResultPages ()
public ResultPages ()
{
}

@ -38,10 +38,12 @@
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Mvc" />
<Reference Include="System.Web.Http" />
<Reference Include="System.Web.ApplicationServices" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResultPages.cs" />
<Compile Include="InputUserName.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

@ -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);
}
/// <summary>
/// Register the specified model and isapprouved.
/// </summary>
/// <param name="model">Model.</param>
/// <param name="isapprouved">If set to <c>true</c> isapprouved.</param>
[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));
}
}
}
/// <summary>
/// Drops the writting.
/// </summary>

@ -1,5 +1,4 @@
using System;
using Yavsc;
using SalesCatalog;
using System.Web.Routing;
using System.Threading.Tasks;

@ -1,5 +1,4 @@
using System;
using Yavsc;
using SalesCatalog;
using System.Web.Routing;
using System.Threading.Tasks;

@ -1,4 +1,5 @@
<%@ Page Title="Devis" Language="C#" Inherits="System.Web.Mvc.ViewPage<Estimate>" MasterPageFile="~/Models/App.master" %>
<%@ Register Assembly="Yavsc.WebControls" TagPrefix="yavsc" Namespace="Yavsc.WebControls" %>
<asp:Content ContentPlaceHolderID="head" ID="head1" runat="server" >
<script type="text/javascript" src="<%=Url.Content("~/Scripts/stupidtable.js")%>"></script>
@ -18,7 +19,12 @@ $("#tbwrts").stupidtable();
<%= Html.ValidationMessage("Title", "*") %>
<br/>
<%= Html.Hidden ("Responsible") %>
<%= Html.LabelFor(model => model.Client) %>:<%=Html.TextBox( "Client" ) %>
<%= Html.LabelFor(model => model.Client) %>:
<% Client.Value = Model.Client ; %>
<yavsc:InputUserName id="Client" name="Client" runat="server">
</yavsc:InputUserName>
<%= Html.ValidationMessage("Client", "*") %>
<br/>
<%= Html.LabelFor(model => model.Description) %>:<%=Html.TextArea( "Description") %>

@ -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);

@ -47,4 +47,6 @@
<data name="role_created"><value>role created</value></data>
<data name="Item_added_to_basket"><value>Item added to basket</value></data>
<data name="Estimate_not_found"><value>Estimate not found</value></data>
<data name="DuplicateEmail"><value>This email adress is already used ({0}).</value></data>
<data name="DuplicateUserName"><value>This user name is already used ({0}).</value></data>
</root>

@ -25,6 +25,7 @@ using System.ComponentModel.DataAnnotations;
namespace Yavsc.Model.RolesAndMembers
{
/// <summary>
/// Register view model.
/// </summary>
@ -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;
}
}
}

Loading…