Starting to test some controller

* BlogUnitTest.cs: Should test the user registration

* NpgsqlBlogProvider.cs: Fixes usage of Npgsql upgrade to latest
  version

* TestAPI.csproj: switch to .Net framework 4.5.1

* AccountController.cs: refactoring password validation

* CalendarController.cs:
* WorkFlowController.cs: SendActivationMessage became an extension
  method

* style.css: menu items already have a background and color, since
  they're `<A>` tags

* Unregister.aspx:
* AccountController.cs: refactoring user registration

* BlogsController.cs: Fixes a confusion between Author and reader ...

* YavscHelpers.cs: refactoring the password reset

* App.master: no more <div class="menuitem">, they're hyperlinks

* Login.aspx:
* Profile.aspx: refactoring the user registration

* BlogEntryCollection.cs: implements a method to filter a given post
  collection in order to be displayed tu a given user or anonymous
This commit is contained in:
Paul Schneider 2015-10-07 11:50:44 +02:00
commit 303aaa5e1b
19 changed files with 218 additions and 65 deletions

View file

@ -126,11 +126,17 @@ namespace Yavsc.Controllers
return View ();
}
public ActionResult RegisterForm()
{
return View ("Register");
}
/// <summary>
/// Register the specified model and returnUrl.
/// </summary>
/// <param name="model">Model.</param>
/// <param name="returnUrl">Return URL.</param>
[HttpPost]
public ActionResult Register (RegisterViewModel model, string returnUrl)
{
ViewData ["returnUrl"] = returnUrl;
@ -138,7 +144,8 @@ namespace Yavsc.Controllers
foreach (string k in ModelState.Keys)
ModelState [k].Errors.Clear ();
return View (model);
}
}
if (ModelState.IsValid) {
if (model.ConfirmPassword != model.Password) {
ModelState.AddModelError ("ConfirmPassword", "Veuillez confirmer votre mot de passe");
@ -164,7 +171,7 @@ namespace Yavsc.Controllers
"déjà enregistré");
return View (model);
case MembershipCreateStatus.Success:
YavscHelpers.SendActivationMessage (user);
Url.SendActivationMessage (user);
ViewData ["username"] = user.UserName;
ViewData ["email"] = user.Email;
return View ("RegistrationPending");
@ -203,14 +210,20 @@ namespace Yavsc.Controllers
}
/// <summary>
/// Unregister the specified confirmed.
/// Unregister the specified id and confirmed.
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="confirmed">If set to <c>true</c> confirmed.</param>
[Authorize]
public ActionResult Unregister (bool confirmed = false)
public ActionResult Unregister (string id, bool confirmed = false)
{
ViewData ["UserName"] = id;
if (!confirmed)
return View ();
string logged = Membership.GetUser ().UserName;
if (logged != id)
if (!Roles.IsUserInRole ("Admin"))
throw new Exception ("Unregister another user");
Membership.DeleteUser (
Membership.GetUser ().UserName);
@ -381,9 +394,13 @@ namespace Yavsc.Controllers
{
if (Request.HttpMethod == "POST") {
StringDictionary errors;
YavscHelpers.ResetPassword (model, out errors);
MembershipUser user;
YavscHelpers.ValidatePasswordReset (model, out errors, out user);
foreach (string key in errors.Keys)
ModelState.AddModelError (key, errors [key]);
if (user != null && ModelState.IsValid)
Url.SendActivationMessage (user);
}
return View (model);
}

View file

@ -185,8 +185,8 @@ namespace Yavsc.Controllers
ViewData ["Avatar"] = pr.avatar;
ViewData ["BlogTitle"] = pr.BlogTitle;
MembershipUser u = Membership.GetUser ();
if (u != null)
ViewData ["Author"] = u.UserName;
ViewData ["Author"] = bec.Author;
if (!pr.BlogVisible) {
// only deliver to admins or owner
if (u == null)
@ -197,6 +197,13 @@ namespace Yavsc.Controllers
return View ("NotAuthorized");
}
}
if (u == null || (u.UserName != bec.Author) && !Roles.IsUserInRole (u.UserName, "Admin")) {
// Filer on allowed posts
BlogEntryCollection filtered = bec.FilterFor((u == null)?null : u.UserName);
UUTBlogEntryCollection nbec = new UUTBlogEntryCollection (bec.Author, bec.Title);
nbec.AddRange (filtered);
View ("UserPost",nbec);
}
}
return View ("UserPost",bec);
}