* YavscHelpers.cs:
* YavscModel.csproj: * HomeController.cs: * AccountController.cs: * RegisterModel.cs: * FrontOfficeApiController.cs: * RegisterViewModel.cs: refactoring * Web.csproj: deploy robots.txt
This commit is contained in:
@ -22,6 +22,7 @@ using System.Web.Profile;
|
||||
using System.Collections.Specialized;
|
||||
using Yavsc.Model;
|
||||
using Yavsc.Model.FrontOffice;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
@ -156,7 +157,7 @@ namespace Yavsc.ApiControllers
|
||||
return new HttpResponseMessage (HttpStatusCode.OK) { Content =
|
||||
new ObjectContent (typeof(string),
|
||||
ex.Message, new ErrorHtmlFormatter (HttpStatusCode.NotAcceptable,
|
||||
LocalizedText.DocTemplateException
|
||||
LocalizedText.DocTemplateException
|
||||
))
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
@ -179,6 +180,43 @@ namespace Yavsc.ApiControllers
|
||||
new TexToPdfFormatter ())
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register the specified model.
|
||||
/// </summary>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="isApprouved">if false, sends a registration validation e-mail.</param>
|
||||
[Authorize(Roles="Admin")]
|
||||
[ValidateAjaxAttribute]
|
||||
public void Register ([FromBody] RegisterModel model, bool isApprouved=true)
|
||||
{
|
||||
MembershipCreateStatus mcs;
|
||||
var user = Membership.CreateUser (
|
||||
model.UserName,
|
||||
model.Password,
|
||||
model.Email,
|
||||
null,
|
||||
null,
|
||||
isApprouved,
|
||||
out mcs);
|
||||
switch (mcs) {
|
||||
case MembershipCreateStatus.DuplicateEmail:
|
||||
ModelState.AddModelError ("Email", "Cette adresse e-mail correspond " +
|
||||
"à un compte utilisateur existant");
|
||||
return ;
|
||||
case MembershipCreateStatus.DuplicateUserName:
|
||||
ModelState.AddModelError ("UserName", "Ce nom d'utilisateur est " +
|
||||
"déjà enregistré");
|
||||
return ;
|
||||
case MembershipCreateStatus.Success:
|
||||
if (!isApprouved)
|
||||
Yavsc.Helpers.YavscHelpers.SendActivationEmail (user);
|
||||
return ;
|
||||
|
||||
default:
|
||||
throw new Exception ( string.Format( "Unexpected membership creation status : {0}", mcs.ToString() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,7 @@ namespace Yavsc.Controllers
|
||||
/// </summary>
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private static string registrationMessage =
|
||||
WebConfigurationManager.AppSettings ["RegistrationMessage"];
|
||||
|
||||
|
||||
string avatarDir = "~/avatars";
|
||||
|
||||
/// <summary>
|
||||
@ -108,40 +106,10 @@ namespace Yavsc.Controllers
|
||||
"déjà enregistré");
|
||||
return View (model);
|
||||
case MembershipCreateStatus.Success:
|
||||
FileInfo fi = new FileInfo (
|
||||
Server.MapPath (registrationMessage));
|
||||
if (!fi.Exists) {
|
||||
ViewData ["Error"] =
|
||||
string.Format (
|
||||
"Erreur inattendue (pas de corps de message " +
|
||||
"à envoyer pour le message de confirmation ({0}))",
|
||||
registrationMessage);
|
||||
return View (model);
|
||||
}
|
||||
|
||||
using (StreamReader sr = fi.OpenText ()) {
|
||||
string body = sr.ReadToEnd ();
|
||||
body = body.Replace ("<%SiteName%>", YavscHelpers.SiteName);
|
||||
body = body.Replace ("<%UserName%>", user.UserName);
|
||||
body = body.Replace ("<%UserActivatonUrl%>",
|
||||
string.Format ("<{0}://{1}/Account/Validate/{2}?key={3}>",
|
||||
Request.Url.Scheme,
|
||||
Request.Url.Authority,
|
||||
user.UserName,
|
||||
user.ProviderUserKey.ToString ()));
|
||||
using (MailMessage msg = new MailMessage (
|
||||
HomeController.Admail, user.Email,
|
||||
string.Format ("Validation de votre compte {0}", YavscHelpers.SiteName),
|
||||
body)) {
|
||||
using (SmtpClient sc = new SmtpClient ()) {
|
||||
sc.Send (msg);
|
||||
}
|
||||
}
|
||||
|
||||
ViewData ["username"] = user.UserName;
|
||||
ViewData ["email"] = user.Email;
|
||||
return View ("RegistrationPending");
|
||||
}
|
||||
YavscHelpers.SendActivationEmail (user);
|
||||
ViewData ["username"] = user.UserName;
|
||||
ViewData ["email"] = user.Email;
|
||||
return View ("RegistrationPending");
|
||||
default:
|
||||
ViewData ["Error"] = "Une erreur inattendue s'est produite" +
|
||||
"a l'enregistrement de votre compte utilisateur" +
|
||||
@ -162,7 +130,8 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
return View ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Changes the password.
|
||||
/// </summary>
|
||||
|
@ -15,6 +15,7 @@ using Npgsql.Web;
|
||||
using ITContentProvider;
|
||||
using Yavsc;
|
||||
using Npgsql.Web.Blog;
|
||||
using Yavsc.Helpers;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
@ -38,18 +39,7 @@ namespace Yavsc.Controllers
|
||||
return name;
|
||||
}
|
||||
}
|
||||
// Administrator email
|
||||
private static string admail =
|
||||
WebConfigurationManager.AppSettings ["AdminEmail"];
|
||||
/// <summary>
|
||||
/// Gets the Administrator email.
|
||||
/// </summary>
|
||||
/// <value>The admail.</value>
|
||||
public static string Admail {
|
||||
get {
|
||||
return admail;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists the referenced assemblies.
|
||||
/// </summary>
|
||||
@ -128,7 +118,7 @@ namespace Yavsc.Controllers
|
||||
|
||||
using (System.Net.Mail.MailMessage msg = new MailMessage(email,OwnerEmail,"[Contact] "+reason,body))
|
||||
{
|
||||
msg.CC.Add(new MailAddress(Admail));
|
||||
msg.CC.Add(new MailAddress(YavscHelpers.Admail));
|
||||
using (System.Net.Mail.SmtpClient sc = new SmtpClient())
|
||||
{
|
||||
sc.Send (msg);
|
||||
|
@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Configuration;
|
||||
using System.Web.Security;
|
||||
using System.IO;
|
||||
using System.Web.Configuration;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
@ -9,6 +13,10 @@ namespace Yavsc.Helpers
|
||||
/// </summary>
|
||||
public static class YavscHelpers
|
||||
{
|
||||
private static string registrationMessage =
|
||||
WebConfigurationManager.AppSettings ["RegistrationMessage"];
|
||||
|
||||
|
||||
private static string siteName = null;
|
||||
/// <summary>
|
||||
/// Gets the name of the site.
|
||||
@ -17,10 +25,60 @@ namespace Yavsc.Helpers
|
||||
public static string SiteName {
|
||||
get {
|
||||
if (siteName == null)
|
||||
siteName = ConfigurationManager.AppSettings ["Name"];
|
||||
siteName = WebConfigurationManager.AppSettings ["Name"];
|
||||
return siteName;
|
||||
}
|
||||
}
|
||||
// Administrator email
|
||||
private static string admail =
|
||||
WebConfigurationManager.AppSettings ["AdminEmail"];
|
||||
/// <summary>
|
||||
/// Gets the Administrator email.
|
||||
/// </summary>
|
||||
/// <value>The admail.</value>
|
||||
public static string Admail {
|
||||
get {
|
||||
return admail;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the activation email.
|
||||
/// </summary>
|
||||
/// <param name="user">User.</param>
|
||||
public static void SendActivationEmail(MembershipUser user) {
|
||||
FileInfo fi = new FileInfo (
|
||||
HttpContext.Current.Server.MapPath (registrationMessage));
|
||||
if (!fi.Exists) {
|
||||
throw new Exception(
|
||||
string.Format (
|
||||
"Erreur inattendue (pas de corps de message " +
|
||||
"à envoyer pour le message de confirmation ({0}))",
|
||||
registrationMessage));
|
||||
}
|
||||
|
||||
using (StreamReader sr = fi.OpenText ()) {
|
||||
string body = sr.ReadToEnd ();
|
||||
body = body.Replace ("<%SiteName%>", YavscHelpers.SiteName);
|
||||
body = body.Replace ("<%UserName%>", user.UserName);
|
||||
body = body.Replace ("<%UserActivatonUrl%>",
|
||||
string.Format ("<{0}://{1}/Account/Validate/{2}?key={3}>",
|
||||
HttpContext.Current.Request.Url.Scheme,
|
||||
HttpContext.Current.Request.Url.Authority,
|
||||
user.UserName,
|
||||
user.ProviderUserKey.ToString ()));
|
||||
using (MailMessage msg = new MailMessage (
|
||||
Admail, user.Email,
|
||||
string.Format ("Validation de votre compte {0}", YavscHelpers.SiteName),
|
||||
body)) {
|
||||
using (SmtpClient sc = new SmtpClient ()) {
|
||||
sc.Send (msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -677,6 +677,7 @@
|
||||
<Content Include="Scripts\stupidtable.js" />
|
||||
<Content Include="Scripts\jquery-ui.js" />
|
||||
<Content Include="Views\Account\Profile.aspx" />
|
||||
<Content Include="robots.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
@ -700,7 +701,6 @@
|
||||
<None Include="packages.config" />
|
||||
<None Include="Scripts\jquery-2.1.3.min.map" />
|
||||
<None Include="Scripts\styles.json" />
|
||||
<None Include="robots.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NpgsqlMRPProviders\NpgsqlMRPProviders.csproj">
|
||||
|
58
yavscModel/RolesAndMemebers/RegisterModel.cs
Normal file
58
yavscModel/RolesAndMemebers/RegisterModel.cs
Normal file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// RegisterModel.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.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Yavsc.Model.RolesAndMembers
|
||||
{
|
||||
/// <summary>
|
||||
/// Register view model.
|
||||
/// </summary>
|
||||
public class RegisterModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the user.
|
||||
/// </summary>
|
||||
/// <value>The name of the user.</value>
|
||||
[Localizable(true)]
|
||||
[Required(ErrorMessage = "S'il vous plait, entrez un nom d'utilisateur")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password.
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
[DisplayName("Mot de passe")]
|
||||
[Required(ErrorMessage = "S'il vous plait, entez un mot de passe")]
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the email.
|
||||
/// </summary>
|
||||
/// <value>The email.</value>
|
||||
[DisplayName("Adresse e-mail")]
|
||||
[Required(ErrorMessage = "S'il vous plait, entrez un e-mail valide")]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -7,38 +7,15 @@ namespace Yavsc.Model.RolesAndMembers
|
||||
/// <summary>
|
||||
/// Register view model.
|
||||
/// </summary>
|
||||
public class RegisterViewModel
|
||||
public class RegisterViewModel : RegisterModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the user.
|
||||
/// </summary>
|
||||
/// <value>The name of the user.</value>
|
||||
[Localizable(true)]
|
||||
[Required(ErrorMessage = "S'il vous plait, entrez un nom d'utilisateur")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password.
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
[DisplayName("Mot de passe")]
|
||||
[Required(ErrorMessage = "S'il vous plait, entez un mot de passe")]
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the confirm password.
|
||||
/// </summary>
|
||||
/// <value>The confirm password.</value>
|
||||
[DisplayName("Confirmation du mot de passe")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the email.
|
||||
/// </summary>
|
||||
/// <value>The email.</value>
|
||||
[DisplayName("Adresse e-mail")]
|
||||
[Required(ErrorMessage = "S'il vous plait, entrez un e-mail valide")]
|
||||
public string Email { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,7 @@
|
||||
<Compile Include="Google\CalendarEventList.cs" />
|
||||
<Compile Include="Google\GDate.cs" />
|
||||
<Compile Include="Google\Resource.cs" />
|
||||
<Compile Include="RolesAndMemebers\RegisterModel.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user