Many fixes
* Profile.aspx: * ProfileEdition.cs: Fixes the username modification * Book-next.aspx: pollution * NpgsqlMembershipProvider.cs: xmldoc * NpgsqlProfileProvider.cs: use default values from configuration * NpgsqlUserNameProvider.cs: Fixes the username detection * test-domain-TestAPI.config: profile dates must be returned as DateTime * instdbws.sql: The conversion to a valid .Net DateTime requires a credible date time as source value, the null one is not supported. * style.css: Fixes the new notification style * AccountController.cs: Fixes the profile edition. Now using the anti forgery key at login time * Book.aspx: * LocalizedText.resx: * LocalizedText.fr.resx: * CalendarApi.cs: * GoogleController.cs: * LocalizedText.Designer.cs: * LocalizedText.fr.Designer.cs: WIP booking * HomeController.cs: code prettying * Global.asax.cs: Limits the usage of titles in a route to the blog controller * OAuth2.cs: Profile values may be of type DBNull ... * T.cs: All translated strings will be Html encoded, as expected from an html helper * YavscHelpers.cs: A new method to build a javascript string... * App.master: * AppAdmin.master: Notification.body is now a js string literal * NoLogin.master: sync with the true master * Login.aspx: Permits the anti forgery key usage * Estimate.aspx: refactoring * Web.config: Fixes a later commit on the catalog name space * Web.csproj: An ajax helper to notify * ChangePasswordModel.cs: * RegisterClientModel.cs: A regexp for user name * LoginModel.cs: A regexp for user name and password * Profile.cs: A regexp for user name, and profile usage fixes * UserManager.cs: Checks for username availability before trying to modify it * YavscModel.csproj: `ProfileEdition` class addition * ChangeLog: should not be indexed * ChangeLog: useless here * ValidateAjaxAttribute.cs: Fixes usage of HtmlFieldPrefix * BookQuery.cs: Start, end hour and role are required * OtherWebException.cs: useless
This commit is contained in:
parent
0a91d3935b
commit
d9d5bb308e
42 changed files with 441 additions and 275 deletions
|
|
@ -16,6 +16,7 @@ using System.Collections.Specialized;
|
|||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Configuration;
|
||||
using Yavsc.Model;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
|
|
@ -61,7 +62,7 @@ namespace Yavsc.Controllers
|
|||
/// <returns>The login.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
/// <param name="returnUrl">Return URL.</param>
|
||||
[HttpPost]
|
||||
[HttpPost,ValidateAntiForgeryToken]
|
||||
public ActionResult Login (LoginModel model, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
|
|
@ -187,7 +188,7 @@ namespace Yavsc.Controllers
|
|||
ViewData ["UserName"] = id;
|
||||
if (!confirmed)
|
||||
return View ();
|
||||
string logged = Membership.GetUser ().UserName;
|
||||
string logged = this.User.Identity.Name;
|
||||
if (logged != id)
|
||||
if (!Roles.IsUserInRole ("Admin"))
|
||||
throw new Exception ("Unregister another user");
|
||||
|
|
@ -250,7 +251,7 @@ namespace Yavsc.Controllers
|
|||
if (id == null)
|
||||
id = Membership.GetUser ().UserName;
|
||||
ViewData ["UserName"] = id;
|
||||
Profile model = new Profile (ProfileBase.Create (id));
|
||||
ProfileEdition model = new ProfileEdition (ProfileBase.Create (id));
|
||||
model.RememberMe = FormsAuthentication.GetAuthCookie (id, true) == null;
|
||||
return View (model);
|
||||
}
|
||||
|
|
@ -265,20 +266,32 @@ namespace Yavsc.Controllers
|
|||
/// <param name="AvatarFile">Avatar file.</param>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult Profile (string id, Profile model, HttpPostedFileBase AvatarFile)
|
||||
public ActionResult Profile (string id, ProfileEdition model, HttpPostedFileBase AvatarFile)
|
||||
{
|
||||
// ASSERT("Membership.GetUser ().UserName is made of simple characters, no slash nor backslash"
|
||||
|
||||
string logdu = Membership.GetUser ().UserName;
|
||||
if (string.IsNullOrWhiteSpace (id))
|
||||
id = logdu;
|
||||
string logdu = User.Identity.Name;
|
||||
if (string.IsNullOrWhiteSpace (id)) {
|
||||
if (string.IsNullOrWhiteSpace (model.UserName)) {
|
||||
model.UserName = logdu;
|
||||
return View (model);
|
||||
} else {
|
||||
id = logdu;
|
||||
}
|
||||
}
|
||||
ViewData ["UserName"] = id;
|
||||
bool editsMyName = (string.Compare(id,logdu)==0);
|
||||
if (!editsMyName)
|
||||
bool editsTheUserName = model.NewUserName!=null&&(string.Compare(id,model.NewUserName)!=0);
|
||||
// Checks authorisation
|
||||
if (logdu!=id)
|
||||
if (!Roles.IsUserInRole ("Admin"))
|
||||
if (!Roles.IsUserInRole ("FrontOffice"))
|
||||
throw new UnauthorizedAccessException ("Your are not authorized to modify this profile");
|
||||
|
||||
// checks availability of a new username
|
||||
if (editsTheUserName)
|
||||
if (!UserManager.IsAvailable (model.NewUserName))
|
||||
ModelState.AddModelError ("UserName",
|
||||
string.Format (
|
||||
LocalizedText.DuplicateUserName,
|
||||
model.NewUserName
|
||||
));
|
||||
if (AvatarFile != null) {
|
||||
// if said valid, move as avatar file
|
||||
// else invalidate the model
|
||||
|
|
@ -295,10 +308,6 @@ namespace Yavsc.Controllers
|
|||
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
||||
AvatarFile.ContentType, "image/png"));
|
||||
}
|
||||
/* Sync the property in the Profile model to display :
|
||||
* string cAvat = HttpContext.Profile.GetPropertyValue ("Avatar") as string;
|
||||
if (cAvat != null) if (model.avatar == null) model.avatar = cAvat;
|
||||
*/
|
||||
if (ModelState.IsValid) {
|
||||
ProfileBase prf = ProfileBase .Create (id);
|
||||
prf.SetPropertyValue ("Name", model.Name);
|
||||
|
|
@ -328,11 +337,12 @@ namespace Yavsc.Controllers
|
|||
prf.SetPropertyValue ("gcalid", model.GoogleCalendar);
|
||||
prf.Save ();
|
||||
|
||||
if (editsMyName) {
|
||||
UserManager.ChangeName (id, model.Name);
|
||||
FormsAuthentication.SetAuthCookie (model.Name, model.RememberMe);
|
||||
if (editsTheUserName) {
|
||||
UserManager.ChangeName (id, model.NewUserName);
|
||||
FormsAuthentication.SetAuthCookie (model.NewUserName, model.RememberMe);
|
||||
model.UserName = model.NewUserName;
|
||||
}
|
||||
YavscHelpers.Notify(ViewData, "Profile enregistré"+((editsMyName)?", nom public inclu.":""));
|
||||
YavscHelpers.Notify(ViewData, "Profile enregistré"+((editsTheUserName)?", nom public inclu.":""));
|
||||
}
|
||||
return View (model);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ namespace Yavsc.Controllers
|
|||
YavscHelpers.Notify(ViewData, msg);
|
||||
return View ("Auth");
|
||||
}
|
||||
SaveToken (gat);
|
||||
SaveToken (HttpContext.Profile,gat);
|
||||
HttpContext.Profile.SetPropertyValue ("gcalapi", true);
|
||||
string returnUrl = (string)Session ["returnUrl"];
|
||||
Session ["returnUrl"] = null;
|
||||
|
|
@ -126,14 +126,14 @@ namespace Yavsc.Controllers
|
|||
/// order to save a descent value as expiration date.
|
||||
/// </summary>
|
||||
/// <param name="gat">Gat.</param>
|
||||
private void SaveToken (AuthToken gat)
|
||||
private void SaveToken (ProfileBase pr, AuthToken gat)
|
||||
{
|
||||
HttpContext.Profile.SetPropertyValue ("gtoken", gat.access_token);
|
||||
pr.SetPropertyValue ("gtoken", gat.access_token);
|
||||
if (gat.refresh_token != null)
|
||||
HttpContext.Profile.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
||||
HttpContext.Profile.SetPropertyValue ("gtokentype", gat.token_type);
|
||||
HttpContext.Profile.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds (gat.expires_in));
|
||||
HttpContext.Profile.Save ();
|
||||
pr.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
||||
pr.SetPropertyValue ("gtokentype", gat.token_type);
|
||||
pr.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds (gat.expires_in));
|
||||
pr.Save ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -161,7 +161,9 @@ namespace Yavsc.Controllers
|
|||
// just set this user as logged on
|
||||
foreach (MembershipUser u in mbrs) {
|
||||
string username = u.UserName;
|
||||
FormsAuthentication.SetAuthCookie (username, true);
|
||||
FormsAuthentication.SetAuthCookie (username, true);
|
||||
/* var upr = ProfileBase.Create (username);
|
||||
SaveToken (upr,gat); */
|
||||
}
|
||||
Session ["returnUrl"] = null;
|
||||
return Redirect (returnUrl);
|
||||
|
|
@ -230,7 +232,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
if (me.url != null)
|
||||
HttpContext.Profile.SetPropertyValue ("WebSite", me.url);
|
||||
SaveToken (gat);
|
||||
SaveToken (HttpContext.Profile,gat);
|
||||
// already done in SaveToken: HttpContext.Profile.Save ();
|
||||
return Redirect (returnUrl);
|
||||
}
|
||||
|
|
@ -256,7 +258,6 @@ namespace Yavsc.Controllers
|
|||
[HttpGet]
|
||||
public ActionResult ChooseCalendar (string returnUrl)
|
||||
{
|
||||
|
||||
bool hasCalAuth = (bool)HttpContext.Profile.GetPropertyValue ("gcalapi");
|
||||
if (!hasCalAuth) {
|
||||
Session ["returnUrl"] = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/ChooseCalendar";
|
||||
|
|
@ -296,8 +297,7 @@ namespace Yavsc.Controllers
|
|||
/// Dates the query.
|
||||
/// </summary>
|
||||
/// <returns>The query.</returns>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
[Authorize,HttpGet]
|
||||
public ActionResult Book ()
|
||||
{
|
||||
return View (new BookQuery ());
|
||||
|
|
@ -308,42 +308,50 @@ namespace Yavsc.Controllers
|
|||
/// </summary>
|
||||
/// <returns>The query.</returns>
|
||||
/// <param name="model">Model.</param>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
[Authorize,HttpPost]
|
||||
public ActionResult Book (BookQuery model)
|
||||
{
|
||||
if (ModelState.IsValid) {
|
||||
DateTime mindate = DateTime.Now;
|
||||
if (model.StartDate < mindate)
|
||||
model.StartDate = mindate;
|
||||
if (model.EndDate < mindate)
|
||||
model.EndDate = mindate.AddYears (1).Date;
|
||||
if (model.StartDate < mindate){
|
||||
ModelState.AddModelError ("StartDate", LocalizedText.FillInAFutureDate);
|
||||
}
|
||||
if (model.EndDate < model.StartDate)
|
||||
ModelState.AddModelError ("EndDate", LocalizedText.StartDateAfterEndDate);
|
||||
|
||||
var muc = Membership.FindUsersByName (model.Person);
|
||||
if (muc.Count == 0) {
|
||||
ModelState.AddModelError ("Person", LocalizedText.Non_existent_user);
|
||||
return View (model);
|
||||
}
|
||||
if (!Roles.IsUserInRole (model.Role)) {
|
||||
ModelState.AddModelError ("Role", LocalizedText.UserNotInThisRole);
|
||||
return View (model);
|
||||
}
|
||||
|
||||
ProfileBase upr = ProfileBase.Create (model.Person);
|
||||
|
||||
string calid = (string)upr.GetPropertyValue ("gcalid");
|
||||
if (string.IsNullOrWhiteSpace (calid)) {
|
||||
var gcalid = upr.GetPropertyValue ("gcalid");
|
||||
if (gcalid is DBNull)
|
||||
ModelState.AddModelError ("Person", LocalizedText.No_calendar_for_this_user);
|
||||
return View (model);
|
||||
}
|
||||
DateTime maxdate = model.EndDate;
|
||||
CalendarApi c = new CalendarApi ();
|
||||
CalendarEventList res;
|
||||
try {
|
||||
var events = c.GetCalendar (calid, mindate, maxdate, upr);
|
||||
|
||||
} catch (OtherWebException ex) {
|
||||
return View ("OtherWebException", ex);
|
||||
if (ModelState.IsValid) {
|
||||
string calid = (string) gcalid;
|
||||
DateTime maxdate = model.EndDate;
|
||||
CalendarApi c = new CalendarApi ();
|
||||
CalendarEventList events;
|
||||
try {
|
||||
events = c.GetCalendar (calid, mindate, maxdate, upr);
|
||||
YavscHelpers.Notify (ViewData, "Google calendar API call success");
|
||||
} catch (WebException ex) {
|
||||
string response;
|
||||
using (var stream = ex.Response.GetResponseStream())
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
response = reader.ReadToEnd();
|
||||
}
|
||||
YavscHelpers.Notify (ViewData,
|
||||
string.Format(
|
||||
"Google calendar API exception {0} : {1}<br><pre>{2}</pre>",
|
||||
ex.Status.ToString(),
|
||||
ex.Message,
|
||||
response));
|
||||
}
|
||||
}
|
||||
}
|
||||
return View (model);
|
||||
|
|
|
|||
|
|
@ -92,7 +92,8 @@ namespace Yavsc.Controllers
|
|||
if (!Request.IsAuthenticated) {
|
||||
ProfileBase anonymousProfile = ProfileBase.Create(anonid);
|
||||
object ac = anonymousProfile.GetPropertyValue ("allowcookies");
|
||||
if (ac is string && ac!="true")
|
||||
|
||||
if (ac is string && ((string)ac)!="true")
|
||||
YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies,
|
||||
"function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+anonid+"' });}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue