* Web.csproj:
* App.master: * IModule.cs: * IRenderer.cs: * DataManager.cs: * ITagHandler.cs: * ViewRenderer.cs: * ResultPages.cs: * BBCodeHelper.cs: * IViewRenderer.cs: * Entity.cs: * YavscModel.csproj: * OAuth2.cs: * Calendar.cs: * Profile.aspx: * ApiClient.cs: * MapTracks.cs: * SalesCatalog.csproj: * EntityQuery.cs: * AdminController.cs: * BlogsController.cs: * GoogleController.cs: * SimpleJsonPostMethod.cs: * JsonReaderError.cs: * AccountController.cs: * JsonReaderError.aspx: * GoogleErrorMessage.cs: * GoogleErrorMessage.aspx: * Catalog.cs: refactoring * Makefile: preprod is from local domain, and prod is for lua.pschneider.fr
This commit is contained in:
parent
f86404fe85
commit
8301159645
29 changed files with 969 additions and 314 deletions
5
Makefile
5
Makefile
|
|
@ -3,7 +3,7 @@ VERSION=1.1
|
||||||
CONFIG=Debug
|
CONFIG=Debug
|
||||||
DESTDIR=build/web/$(CONFIG)
|
DESTDIR=build/web/$(CONFIG)
|
||||||
COPYUNCHANGED="false"
|
COPYUNCHANGED="false"
|
||||||
PREPRODHOST=yavsc.pschneider.fr
|
PREPRODHOST=yavsc.localdomain
|
||||||
|
|
||||||
all: deploy
|
all: deploy
|
||||||
|
|
||||||
|
|
@ -27,6 +27,9 @@ clean:
|
||||||
rsync-preprod: deploy
|
rsync-preprod: deploy
|
||||||
rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOST):/srv/www/yavsc
|
rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOST):/srv/www/yavsc
|
||||||
|
|
||||||
|
rsync-prod: deploy
|
||||||
|
rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOST):/srv/www/lua
|
||||||
|
|
||||||
rsync-local:
|
rsync-local:
|
||||||
rsync -ravu build/web/$(CONFIG)/ root@localhost:/srv/www/yavsc
|
rsync -ravu build/web/$(CONFIG)/ root@localhost:/srv/www/yavsc
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace SalesCatalog.Model
|
||||||
Brand b = this.GetBrand (brandName);
|
Brand b = this.GetBrand (brandName);
|
||||||
if (b == null)
|
if (b == null)
|
||||||
return false;
|
return false;
|
||||||
//assert(Brands.Length>0);
|
//ASSERT Brands.Length>0;
|
||||||
List<Brand> nb = new List<Brand> (Brands);
|
List<Brand> nb = new List<Brand> (Brands);
|
||||||
nb.Remove (b);
|
nb.Remove (b);
|
||||||
Brands = nb.ToArray ();
|
Brands = nb.ToArray ();
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<RootNamespace>SalesCatalog</RootNamespace>
|
<RootNamespace>SalesCatalog</RootNamespace>
|
||||||
<AssemblyName>SalesCatalog</AssemblyName>
|
<AssemblyName>SalesCatalog</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ namespace Yavsc.WebControls
|
||||||
|
|
||||||
protected override void RenderContents (HtmlTextWriter writer)
|
protected override void RenderContents (HtmlTextWriter writer)
|
||||||
{
|
{
|
||||||
if (ResultCount > 0) {
|
if (ResultCount > 0 && ResultCount > ResultsPerPage ) {
|
||||||
writer.WriteEncodedText (Text);
|
writer.WriteEncodedText (Text);
|
||||||
int pageCount = ((ResultCount-1) / ResultsPerPage) + 1;
|
int pageCount = ((ResultCount-1) / ResultsPerPage) + 1;
|
||||||
for (int pi = (CurrentPage < 5) ? 0 : CurrentPage - 5; pi < pageCount && pi < CurrentPage + 5; pi++) {
|
for (int pi = (CurrentPage < 5) ? 0 : CurrentPage - 5; pi < pageCount && pi < CurrentPage + 5; pi++) {
|
||||||
|
|
@ -105,9 +105,10 @@ namespace Yavsc.WebControls
|
||||||
writer.RenderEndTag ();
|
writer.RenderEndTag ();
|
||||||
writer.Write (" ");
|
writer.Write (" ");
|
||||||
}
|
}
|
||||||
writer.Write ("("+ResultCount.ToString()+" resultat(s))");
|
writer.Write (ResultCount.ToString () + " resultat");
|
||||||
} else {
|
if (ResultCount>1) writer.Write("s");
|
||||||
writer.Write ("(Pas de resultat)");
|
} else if ( ResultCount == 0 ) {
|
||||||
|
writer.Write ("Pas de resultat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,12 @@ namespace Yavsc.Admin
|
||||||
{
|
{
|
||||||
da = datac;
|
da = datac;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Export CreateBackup ()
|
public Export CreateBackup ()
|
||||||
{
|
{
|
||||||
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
|
Environment.SetEnvironmentVariable("PGPASSWORD", da.Password);
|
||||||
Export e = new Export ();
|
|
||||||
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMddhhmmss")+".tar";
|
string fileName = da.BackupPrefix + "-" + DateTime.Now.ToString ("yyyyMMddhhmmss")+".tar";
|
||||||
FileInfo ofi = new FileInfo (fileName);
|
FileInfo ofi = new FileInfo (fileName);
|
||||||
|
Export e = new Export ();
|
||||||
e.FileName = ofi.FullName;
|
e.FileName = ofi.FullName;
|
||||||
/*
|
/*
|
||||||
Exec ("pg_dump", string.Format (
|
Exec ("pg_dump", string.Format (
|
||||||
|
|
@ -65,10 +64,12 @@ namespace Yavsc.Admin
|
||||||
*/
|
*/
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskOutput CreateDb ()
|
public TaskOutput CreateDb ()
|
||||||
{
|
{
|
||||||
return Restore ("freshinstall", false);
|
return Restore ("freshinstall", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Export TagBackup (string filename, string [] tags)
|
public Export TagBackup (string filename, string [] tags)
|
||||||
{
|
{
|
||||||
/* FileInfo fi = new FileInfo (filename);
|
/* FileInfo fi = new FileInfo (filename);
|
||||||
|
|
|
||||||
|
|
@ -229,19 +229,21 @@ namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
string username = Membership.GetUser ().UserName;
|
string username = Membership.GetUser ().UserName;
|
||||||
ViewData ["UserName"] = username;
|
ViewData ["UserName"] = username;
|
||||||
if (AvatarFile != null) {
|
if (AvatarFile == null) {
|
||||||
|
// do not update <c>avatar</c> to null since
|
||||||
|
// it's not in the model.
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// if said valid, move as avatar file
|
||||||
|
// else invalidate the model
|
||||||
if (AvatarFile.ContentType == "image/png") {
|
if (AvatarFile.ContentType == "image/png") {
|
||||||
string avdir = Server.MapPath (AvatarDir);
|
string avdir = Server.MapPath (AvatarDir);
|
||||||
string avpath = Path.Combine (avdir, username + ".png");
|
string avpath = Path.Combine (avdir, username + ".png");
|
||||||
AvatarFile.SaveAs (avpath);
|
AvatarFile.SaveAs (avpath);
|
||||||
string avuri = avpath.Substring (
|
model.avatar =
|
||||||
AppDomain.CurrentDomain.BaseDirectory.Length);
|
Path.Combine(AvatarDir.Substring(1),username)+".png";
|
||||||
avuri = avuri.Replace (" ", "+");
|
|
||||||
avuri = Request.Url.Scheme + "://" + Request.Url.Authority + "/" + avuri;
|
|
||||||
HttpContext.Profile.SetPropertyValue ("avatar", avuri);
|
|
||||||
HttpContext.Profile.Save ();
|
|
||||||
model.avatar = avuri;
|
|
||||||
} else
|
} else
|
||||||
ModelState.AddModelError ("Avatar",
|
ModelState.AddModelError ("Avatar",
|
||||||
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
string.Format ("Image type {0} is not supported (suported formats : {1})",
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ namespace Yavsc.Controllers
|
||||||
Roles.AddUserToRole (model.UserName, adminRoleName);
|
Roles.AddUserToRole (model.UserName, adminRoleName);
|
||||||
ViewData ["Message"] = model.UserName + " was added to the role '" + adminRoleName + "'";
|
ViewData ["Message"] = model.UserName + " was added to the role '" + adminRoleName + "'";
|
||||||
} else {
|
} else {
|
||||||
// assert (Roles.RoleExists (adminRoleName))
|
// ASSERT (Roles.RoleExists (adminRoleName))
|
||||||
string [] admins = Roles.GetUsersInRole (adminRoleName);
|
string [] admins = Roles.GetUsersInRole (adminRoleName);
|
||||||
if (admins.Length > 0) {
|
if (admins.Length > 0) {
|
||||||
if (! admins.Contains (Membership.GetUser ().UserName)) {
|
if (! admins.Contains (Membership.GetUser ().UserName)) {
|
||||||
|
|
|
||||||
|
|
@ -239,9 +239,8 @@ namespace Yavsc.Controllers
|
||||||
public ActionResult Avatar (string user)
|
public ActionResult Avatar (string user)
|
||||||
{
|
{
|
||||||
ProfileBase pr = ProfileBase.Create (user);
|
ProfileBase pr = ProfileBase.Create (user);
|
||||||
|
|
||||||
string avpath = (string) pr.GetPropertyValue ("avatar");
|
string avpath = (string) pr.GetPropertyValue ("avatar");
|
||||||
if (avpath == null) {
|
if (avpath==null) {
|
||||||
FileInfo fia = new FileInfo (Server.MapPath (defaultAvatar));
|
FileInfo fia = new FileInfo (Server.MapPath (defaultAvatar));
|
||||||
return File (fia.OpenRead (), defaultAvatarMimetype);
|
return File (fia.OpenRead (), defaultAvatarMimetype);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,27 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Web;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Text;
|
|
||||||
using Mono.Security.Protocol.Tls;
|
|
||||||
using System.Net;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Yavsc.Model;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web.Security;
|
||||||
|
using Mono.Security.Protocol.Tls;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Yavsc.Model;
|
||||||
using Yavsc.Model.Google;
|
using Yavsc.Model.Google;
|
||||||
using Yavsc.Model.RolesAndMembers;
|
using Yavsc.Model.RolesAndMembers;
|
||||||
using System.Web.Security;
|
using Yavsc.Helpers.Google;
|
||||||
using System.Web.Profile;
|
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
|
|
||||||
public class GoogleController : Controller
|
public class GoogleController : Controller
|
||||||
{
|
{
|
||||||
// datetime format : yyyy-mm-ddTHH:MM:ss
|
|
||||||
// 2015-01-01T10:00:00-07:00
|
|
||||||
private string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw";
|
|
||||||
|
|
||||||
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
|
||||||
private static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
|
|
||||||
private static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
|
|
||||||
|
|
||||||
private static string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com";
|
|
||||||
private static string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL";
|
|
||||||
|
|
||||||
private static string[] SCOPES = {
|
|
||||||
"openid",
|
|
||||||
"profile",
|
|
||||||
"email"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static string tokenUri = "https://accounts.google.com/o/oauth2/token";
|
|
||||||
private static string authUri = "https://accounts.google.com/o/oauth2/auth";
|
|
||||||
private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
|
|
||||||
private string timeZone = "+02:00";
|
|
||||||
|
|
||||||
private string SetSessionSate ()
|
private string SetSessionSate ()
|
||||||
{
|
{
|
||||||
|
|
@ -52,63 +31,50 @@ namespace Yavsc.Controllers
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string AuthGRU {
|
||||||
|
get {
|
||||||
|
return Request.Url.Scheme + "://" +
|
||||||
|
Request.Url.Authority + "/Google/Auth";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CalendarGRU {
|
||||||
|
get {
|
||||||
|
return Request.Url.Scheme + "://" +
|
||||||
|
Request.Url.Authority + "/Google/CalAuth";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Login (string returnUrl)
|
public void Login (string returnUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace (returnUrl))
|
if (string.IsNullOrWhiteSpace (returnUrl))
|
||||||
returnUrl = "/";
|
returnUrl = "/";
|
||||||
Session ["returnUrl"] = returnUrl;
|
Session ["returnUrl"] = returnUrl;
|
||||||
|
OAuth2 oa = new OAuth2 (AuthGRU);
|
||||||
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/Auth";
|
oa.Login (Response, SetSessionSate ());
|
||||||
string scope = string.Join ("%20", SCOPES);
|
|
||||||
|
|
||||||
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false",
|
|
||||||
CLIENT_ID, redirectUri, scope, SetSessionSate ());
|
|
||||||
|
|
||||||
GetAuthResponse (prms);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GetAuthResponse (string prms)
|
|
||||||
{
|
|
||||||
string cont = null;
|
|
||||||
WebRequest wr = WebRequest.Create (authUri + "?" + prms);
|
|
||||||
wr.Method = "GET";
|
|
||||||
using (
|
|
||||||
WebResponse response = wr.GetResponse ()) {
|
|
||||||
string resQuery = response.ResponseUri.Query;
|
|
||||||
cont = HttpUtility.ParseQueryString (resQuery) ["continue"];
|
|
||||||
response.Close ();
|
|
||||||
|
|
||||||
}
|
|
||||||
wr.Abort ();
|
|
||||||
|
|
||||||
Response.Redirect (cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Authorize]
|
|
||||||
public void GetCalAuth ()
|
|
||||||
{
|
|
||||||
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/CalAuth";
|
|
||||||
string scope = string.Join ("%20", SCOPES);
|
|
||||||
scope += "%20https://www.googleapis.com/auth/calendar";
|
|
||||||
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false&access_type=offline",
|
|
||||||
CLIENT_ID, redirectUri, scope, SetSessionSate ());
|
|
||||||
Session ["calasked"] = true;
|
|
||||||
GetAuthResponse (prms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
/// <summary>
|
||||||
|
/// Called after the Google authorizations screen,
|
||||||
|
/// we assume that <c>Session</c> contains a redirectUrl entry
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The auth.</returns>
|
||||||
public ActionResult CalAuth ()
|
public ActionResult CalAuth ()
|
||||||
{
|
{
|
||||||
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/CalAuth";
|
string msg;
|
||||||
AuthToken gat = GetToken (TokenPostDataFromCode(redirectUri, GetCodeFromRequest()));
|
OAuth2 oa = new OAuth2 (CalendarGRU);
|
||||||
|
|
||||||
|
AuthToken gat = oa.GetToken (Request, (string)Session ["state"], out msg);
|
||||||
if (gat == null) {
|
if (gat == null) {
|
||||||
|
ViewData ["Message"] = msg;
|
||||||
return View ("Auth");
|
return View ("Auth");
|
||||||
}
|
}
|
||||||
SaveToken (gat);
|
SaveToken (gat);
|
||||||
HttpContext.Profile.SetPropertyValue ("gcalapi", true);
|
HttpContext.Profile.SetPropertyValue ("gcalapi", true);
|
||||||
string returnUrl = (string)Session ["returnUrl"];
|
string returnUrl = (string)Session ["returnUrl"];
|
||||||
Session ["returnUrl"]=null;
|
Session ["returnUrl"] = null;
|
||||||
return Redirect (returnUrl);
|
return Redirect (returnUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,130 +85,50 @@ namespace Yavsc.Controllers
|
||||||
/// order to save a descent value as expiration date.
|
/// order to save a descent value as expiration date.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gat">Gat.</param>
|
/// <param name="gat">Gat.</param>
|
||||||
private void SaveToken(AuthToken gat)
|
private void SaveToken (AuthToken gat)
|
||||||
{
|
{
|
||||||
HttpContext.Profile.SetPropertyValue ("gtoken", gat.access_token);
|
HttpContext.Profile.SetPropertyValue ("gtoken", gat.access_token);
|
||||||
if (gat.refresh_token!=null)
|
if (gat.refresh_token != null)
|
||||||
HttpContext.Profile.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
HttpContext.Profile.SetPropertyValue ("grefreshtoken", gat.refresh_token);
|
||||||
HttpContext.Profile.SetPropertyValue ("gtokentype", gat.token_type);
|
HttpContext.Profile.SetPropertyValue ("gtokentype", gat.token_type);
|
||||||
HttpContext.Profile.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds(gat.expires_in));
|
HttpContext.Profile.SetPropertyValue ("gtokenexpir", DateTime.Now.AddSeconds (gat.expires_in));
|
||||||
HttpContext.Profile.Save ();
|
HttpContext.Profile.Save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCodeFromRequest()
|
|
||||||
{
|
|
||||||
string code = Request.Params ["code"];
|
|
||||||
string error = Request.Params ["error"];
|
|
||||||
if (error != null) {
|
|
||||||
ViewData ["Message"] =
|
|
||||||
string.Format (LocalizedText.Google_error,
|
|
||||||
LocalizedText.ResourceManager.GetString (error));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string state = Request.Params ["state"];
|
|
||||||
if (state != null && string.Compare ((string)Session ["state"], state) != 0) {
|
|
||||||
ViewData ["Message"] =
|
|
||||||
LocalizedText.ResourceManager.GetString ("invalid request state");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AuthToken GetToken (string postdata)
|
|
||||||
{
|
|
||||||
Byte[] bytes = System.Text.Encoding.UTF8.GetBytes (postdata);
|
|
||||||
HttpWebRequest webreq = WebRequest.CreateHttp (tokenUri);
|
|
||||||
webreq.KeepAlive = false;
|
|
||||||
webreq.Timeout = 5000;
|
|
||||||
webreq.Proxy = null;
|
|
||||||
// Not implemented: webreq.ServicePoint.ConnectionLeaseTimeout = 5000;
|
|
||||||
webreq.ServicePoint.MaxIdleTime = 5000;
|
|
||||||
webreq.Method = "POST";
|
|
||||||
webreq.Accept = "application/json";
|
|
||||||
webreq.ContentType = "application/x-www-form-urlencoded";
|
|
||||||
webreq.ContentLength = bytes.Length;
|
|
||||||
|
|
||||||
using (Stream dataStream = webreq.GetRequestStream ()) {
|
|
||||||
dataStream.Write (bytes, 0, bytes.Length);
|
|
||||||
dataStream.Close ();
|
|
||||||
}
|
|
||||||
AuthToken gat =null;
|
|
||||||
|
|
||||||
using (WebResponse response = webreq.GetResponse ()) {
|
|
||||||
using (Stream responseStream = response.GetResponseStream ()) {
|
|
||||||
using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8)) {
|
|
||||||
string responseStr = readStream.ReadToEnd ();
|
|
||||||
gat = JsonConvert.DeserializeObject<AuthToken> (responseStr);
|
|
||||||
readStream.Close ();
|
|
||||||
}
|
|
||||||
responseStream.Close ();
|
|
||||||
}
|
|
||||||
response.Close();
|
|
||||||
}
|
|
||||||
webreq.Abort ();
|
|
||||||
|
|
||||||
return gat;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string TokenPostDataFromCode(string redirectUri, string code)
|
|
||||||
{
|
|
||||||
string postdata =
|
|
||||||
string.Format (
|
|
||||||
"redirect_uri={0}&client_id={1}&client_secret={2}&code={3}&grant_type=authorization_code",
|
|
||||||
HttpUtility.UrlEncode (redirectUri),
|
|
||||||
HttpUtility.UrlEncode (CLIENT_ID),
|
|
||||||
HttpUtility.UrlEncode (CLIENT_SECRET),
|
|
||||||
HttpUtility.UrlEncode (code));
|
|
||||||
return postdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult Auth ()
|
public ActionResult Auth ()
|
||||||
{
|
{
|
||||||
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/Auth";
|
string msg;
|
||||||
AuthToken gat = GetToken (TokenPostDataFromCode( redirectUri, GetCodeFromRequest()));
|
OAuth2 oa = new OAuth2 (AuthGRU);
|
||||||
|
AuthToken gat = oa.GetToken (Request, (string)Session ["state"], out msg);
|
||||||
if (gat == null) {
|
if (gat == null) {
|
||||||
|
ViewData ["Message"] = msg;
|
||||||
return View ();
|
return View ();
|
||||||
}
|
}
|
||||||
string returnUrl = (string)Session ["returnUrl"];
|
string returnUrl = (string)Session ["returnUrl"];
|
||||||
|
|
||||||
SignIn regmod = new SignIn ();
|
SignIn regmod = new SignIn ();
|
||||||
HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me");
|
|
||||||
webreppro.ContentType = "application/http";
|
|
||||||
webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token);
|
|
||||||
webreppro.Method = "GET";
|
|
||||||
using (WebResponse proresp = webreppro.GetResponse ()) {
|
|
||||||
using (Stream prresponseStream = proresp.GetResponseStream ()) {
|
|
||||||
using (StreamReader readproresp = new StreamReader (prresponseStream, Encoding.UTF8)) {
|
|
||||||
string prresponseStr = readproresp.ReadToEnd ();
|
|
||||||
People me = JsonConvert.DeserializeObject<People> (prresponseStr);
|
|
||||||
// TODO use me.id to retreive an existing user
|
|
||||||
string accEmail = me.emails.Where (x => x.type == "account").First ().value;
|
|
||||||
MembershipUserCollection mbrs = Membership.FindUsersByEmail (accEmail);
|
|
||||||
if (mbrs.Count == 1) {
|
|
||||||
// TODO check the google id
|
|
||||||
// just set this user as logged on
|
|
||||||
FormsAuthentication.SetAuthCookie (me.displayName, true);
|
|
||||||
Session ["returnUrl"] = null;
|
|
||||||
prresponseStream.Close ();
|
|
||||||
proresp.Close ();
|
|
||||||
webreppro.Abort ();
|
|
||||||
return Redirect (returnUrl);
|
|
||||||
}
|
|
||||||
// else create the account
|
|
||||||
regmod.Email = accEmail;
|
|
||||||
regmod.UserName = me.displayName;
|
|
||||||
Session ["me"] = me;
|
|
||||||
Session ["GoogleAuthToken"] = gat;
|
|
||||||
webreppro.Abort ();
|
|
||||||
|
|
||||||
|
People me = PeopleApi.GetMe (gat);
|
||||||
}
|
// TODO use me.id to retreive an existing user
|
||||||
prresponseStream.Close ();
|
string accEmail = me.emails.Where (x => x.type == "account").First ().value;
|
||||||
}
|
MembershipUserCollection mbrs = Membership.FindUsersByEmail (accEmail);
|
||||||
proresp.Close ();
|
if (mbrs.Count == 1) {
|
||||||
}
|
// TODO check the google id
|
||||||
webreppro.Abort ();
|
// just set this user as logged on
|
||||||
|
FormsAuthentication.SetAuthCookie (me.displayName, true);
|
||||||
|
Session ["returnUrl"] = null;
|
||||||
|
|
||||||
|
return Redirect (returnUrl);
|
||||||
|
}
|
||||||
|
// else create the account
|
||||||
|
regmod.Email = accEmail;
|
||||||
|
regmod.UserName = me.displayName;
|
||||||
|
Session ["me"] = me;
|
||||||
|
Session ["GoogleAuthToken"] = gat;
|
||||||
return Auth (regmod);
|
return Auth (regmod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,22 +197,12 @@ namespace Yavsc.Controllers
|
||||||
return View (regmod);
|
return View (regmod);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetFreshGoogleCredential (ProfileBase pr)
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet]
|
||||||
|
ActionResult PushPos ()
|
||||||
{
|
{
|
||||||
string token = (string) pr.GetPropertyValue ("gtoken");
|
return View ();
|
||||||
string token_type = (string) pr.GetPropertyValue ("gtokentype");
|
|
||||||
DateTime token_exp = (DateTime) pr.GetPropertyValue ("gtokenexpir");
|
|
||||||
if (token_exp < DateTime.Now) {
|
|
||||||
string refresh_token = (string) pr.GetPropertyValue ("grefreshtoken");
|
|
||||||
AuthToken gat = GetToken(
|
|
||||||
string.Format("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}",
|
|
||||||
CLIENT_ID, CLIENT_SECRET, refresh_token));
|
|
||||||
token = gat.access_token;
|
|
||||||
pr.SetPropertyValue ("gtoken", token);
|
|
||||||
pr.Save ();
|
|
||||||
// assert gat.token_type == token_type
|
|
||||||
}
|
|
||||||
return token_type + " " + token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
|
@ -336,29 +212,15 @@ namespace Yavsc.Controllers
|
||||||
Session ["ChooseCalReturnUrl"] = returnUrl;
|
Session ["ChooseCalReturnUrl"] = returnUrl;
|
||||||
bool hasCalAuth = (bool)HttpContext.Profile.GetPropertyValue ("gcalapi");
|
bool hasCalAuth = (bool)HttpContext.Profile.GetPropertyValue ("gcalapi");
|
||||||
if (!hasCalAuth) {
|
if (!hasCalAuth) {
|
||||||
Session["returnUrl"] = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/ChooseCalendar";
|
Session ["returnUrl"] = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/ChooseCalendar";
|
||||||
return RedirectToAction ("GetCalAuth");
|
return RedirectToAction ("GetCalAuth");
|
||||||
}
|
}
|
||||||
|
string cred = OAuth2.GetFreshGoogleCredential (HttpContext.Profile);
|
||||||
string cred = GetFreshGoogleCredential (HttpContext.Profile);
|
string json;
|
||||||
|
Calendar c = new Calendar ();
|
||||||
HttpWebRequest webreq = WebRequest.CreateHttp (getCalListUri);
|
CalendarList cl = c.GetCalendars (cred, out json);
|
||||||
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
ViewData ["json"] = json;
|
||||||
webreq.Method = "GET";
|
return View (cl);
|
||||||
webreq.ContentType = "application/http";
|
|
||||||
CalendarList res = null;
|
|
||||||
using (WebResponse resp = webreq.GetResponse ()) {
|
|
||||||
using (Stream respstream = resp.GetResponseStream ()) {
|
|
||||||
using (StreamReader readresp = new StreamReader (respstream, Encoding.UTF8)) {
|
|
||||||
string responseStr = readresp.ReadToEnd ();
|
|
||||||
res = JsonConvert.DeserializeObject<CalendarList> (responseStr);
|
|
||||||
ViewData ["json"] = responseStr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resp.Close ();
|
|
||||||
}
|
|
||||||
webreq.Abort ();
|
|
||||||
return View (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -368,7 +230,7 @@ namespace Yavsc.Controllers
|
||||||
HttpContext.Profile.SetPropertyValue ("gcalid", calchoice);
|
HttpContext.Profile.SetPropertyValue ("gcalid", calchoice);
|
||||||
HttpContext.Profile.Save ();
|
HttpContext.Profile.Save ();
|
||||||
|
|
||||||
string returnUrl = (string) Session ["ChooseCalReturnUrl"];
|
string returnUrl = (string)Session ["ChooseCalReturnUrl"];
|
||||||
if (returnUrl != null) {
|
if (returnUrl != null) {
|
||||||
Session ["ChooseCalReturnUrl"] = null;
|
Session ["ChooseCalReturnUrl"] = null;
|
||||||
return Redirect (returnUrl);
|
return Redirect (returnUrl);
|
||||||
|
|
@ -378,14 +240,14 @@ namespace Yavsc.Controllers
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult DateQuery()
|
public ActionResult DateQuery ()
|
||||||
{
|
{
|
||||||
return View (new AskForADate ());
|
return View (new AskForADate ());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult DateQuery(AskForADate model)
|
public ActionResult DateQuery (AskForADate model)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid) {
|
if (ModelState.IsValid) {
|
||||||
if (model.MinDate < DateTime.Now) {
|
if (model.MinDate < DateTime.Now) {
|
||||||
|
|
@ -397,14 +259,14 @@ namespace Yavsc.Controllers
|
||||||
return View (model);
|
return View (model);
|
||||||
}
|
}
|
||||||
var muc = Membership.FindUsersByName (model.UserName);
|
var muc = Membership.FindUsersByName (model.UserName);
|
||||||
if (muc.Count==0) {
|
if (muc.Count == 0) {
|
||||||
ModelState.AddModelError ("UserName", "Non existent user");
|
ModelState.AddModelError ("UserName", "Non existent user");
|
||||||
return View (model);
|
return View (model);
|
||||||
}
|
}
|
||||||
ProfileBase upr = ProfileBase.Create (model.UserName);
|
ProfileBase upr = ProfileBase.Create (model.UserName);
|
||||||
|
|
||||||
string calid = (string) upr.GetPropertyValue ("gcalid");
|
string calid = (string)upr.GetPropertyValue ("gcalid");
|
||||||
if (string.IsNullOrWhiteSpace(calid)) {
|
if (string.IsNullOrWhiteSpace (calid)) {
|
||||||
ModelState.AddModelError ("UserName", "L'utilisateur n'a pas de calendrier Google associé.");
|
ModelState.AddModelError ("UserName", "L'utilisateur n'a pas de calendrier Google associé.");
|
||||||
return View (model);
|
return View (model);
|
||||||
}
|
}
|
||||||
|
|
@ -415,52 +277,17 @@ namespace Yavsc.Controllers
|
||||||
DateTime maxdate = model.MaxDate;
|
DateTime maxdate = model.MaxDate;
|
||||||
maxdate = maxdate.AddHours (int.Parse (model.MaxTime.Substring (0, 2)));
|
maxdate = maxdate.AddHours (int.Parse (model.MaxTime.Substring (0, 2)));
|
||||||
maxdate = maxdate.AddMinutes (int.Parse (model.MaxTime.Substring (3, 2)));
|
maxdate = maxdate.AddMinutes (int.Parse (model.MaxTime.Substring (3, 2)));
|
||||||
string uri = string.Format (
|
|
||||||
getCalEntriesUri, HttpUtility.UrlEncode(calid)) +
|
|
||||||
string.Format ("?orderBy=startTime&singleEvents=true&timeMin={0}&timeMax={1}&key="+API_KEY,
|
|
||||||
HttpUtility.UrlEncode(mindate.ToString (dateFormat)+timeZone) ,
|
|
||||||
HttpUtility.UrlEncode(maxdate.ToString (dateFormat)+timeZone) );
|
|
||||||
|
|
||||||
HttpWebRequest webreq = WebRequest.CreateHttp (uri);
|
Calendar c = new Calendar ();
|
||||||
string cred = GetFreshGoogleCredential (upr);
|
CalendarEntryList res;
|
||||||
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
string responseStr;
|
||||||
webreq.Method = "GET";
|
|
||||||
webreq.ContentType = "application/http";
|
|
||||||
CalendarEntryList res = null;
|
|
||||||
try {
|
try {
|
||||||
using (WebResponse resp = webreq.GetResponse ()) {
|
res = c.GetCalendar (calid, mindate, maxdate, upr, out responseStr);
|
||||||
using (Stream respstream = resp.GetResponseStream ()) {
|
} catch (GoogleErrorException ex) {
|
||||||
using (StreamReader readresp = new StreamReader (respstream, Encoding.UTF8)) {
|
ViewData ["Title"] = ex.Title;
|
||||||
string responseStr = readresp.ReadToEnd ();
|
ViewData ["Content"] = ex.Content;
|
||||||
try {
|
return View ("GoogleErrorMessage", ex);
|
||||||
ViewData ["json"] = responseStr;
|
|
||||||
res = JsonConvert.DeserializeObject<CalendarEntryList> (responseStr);
|
|
||||||
}
|
|
||||||
catch (JsonReaderException ex) {
|
|
||||||
respstream.Close ();
|
|
||||||
resp.Close ();
|
|
||||||
webreq.Abort ();
|
|
||||||
return View ("JsonReaderError", new JsonReaderError() {Text= responseStr, Excepx = ex});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
respstream.Close ();
|
|
||||||
}
|
|
||||||
resp.Close ();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (WebException ex)
|
|
||||||
{
|
|
||||||
string message;
|
|
||||||
using (var stream = ex.Response.GetResponseStream())
|
|
||||||
using (var reader = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
message = reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
webreq.Abort ();
|
|
||||||
return View ("JsonReaderError", new JsonReaderError() {Text= message, Excepx = ex});
|
|
||||||
|
|
||||||
}
|
|
||||||
webreq.Abort ();
|
|
||||||
return View (res);
|
return View (res);
|
||||||
}
|
}
|
||||||
return View (model);
|
return View (model);
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ namespace Yavsc.Helpers
|
||||||
|
|
||||||
for (int i = 1; i<=m1; i++) {
|
for (int i = 1; i<=m1; i++) {
|
||||||
string t1 = toc [i, 0, 0];
|
string t1 = toc [i, 0, 0];
|
||||||
// assert t1 != null
|
// ASSERT t1 != null
|
||||||
ttb.AppendFormat ("<a href=\"#s{0}\">{0}) {1}</a><br/>\n", i, t1);
|
ttb.AppendFormat ("<a href=\"#s{0}\">{0}) {1}</a><br/>\n", i, t1);
|
||||||
|
|
||||||
for (int j = 1; j <= m2; j++) {
|
for (int j = 1; j <= m2; j++) {
|
||||||
|
|
|
||||||
58
web/Helpers/Google/ApiClient.cs
Normal file
58
web/Helpers/Google/ApiClient.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
//
|
||||||
|
// Manager.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 Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
|
||||||
|
public class ApiClient
|
||||||
|
{
|
||||||
|
protected static string CLIENT_ID = "325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com";
|
||||||
|
protected static string CLIENT_SECRET = "MaxYcvJJCs2gDGvaELZbzwfL";
|
||||||
|
protected static string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw";
|
||||||
|
/* // to use in descendence
|
||||||
|
*
|
||||||
|
protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||||
|
private static string authUri = "https://accounts.google.com/o/oauth2/auth";
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static string scopeTracks = "https://www.googleapis.com/auth/tracks";
|
||||||
|
protected static string scopeCalendar = "https://www.googleapis.com/auth/calendar";
|
||||||
|
protected static string[] scopeOpenid = {
|
||||||
|
"openid",
|
||||||
|
"profile",
|
||||||
|
"email"
|
||||||
|
};
|
||||||
|
|
||||||
|
// private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
103
web/Helpers/Google/Calendar.cs
Normal file
103
web/Helpers/Google/Calendar.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
//
|
||||||
|
// Calendar.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 Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
public class Calendar: ApiClient
|
||||||
|
{
|
||||||
|
protected static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
|
||||||
|
protected static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
|
||||||
|
|
||||||
|
private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
|
||||||
|
private string timeZone = "+01:00";
|
||||||
|
|
||||||
|
public CalendarList GetCalendars (string cred, out string json)
|
||||||
|
{
|
||||||
|
CalendarList res = null;
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (getCalListUri);
|
||||||
|
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
||||||
|
webreq.Method = "GET";
|
||||||
|
webreq.ContentType = "application/http";
|
||||||
|
using (WebResponse resp = webreq.GetResponse ()) {
|
||||||
|
using (Stream respstream = resp.GetResponseStream ()) {
|
||||||
|
using (StreamReader readresp = new StreamReader (respstream, Encoding.UTF8)) {
|
||||||
|
json = readresp.ReadToEnd ();
|
||||||
|
res = JsonConvert.DeserializeObject<CalendarList> (json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.Close ();
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CalendarEntryList GetCalendar (string calid, DateTime mindate, DateTime maxdate, ProfileBase upr, out string responseStr)
|
||||||
|
{
|
||||||
|
string uri = string.Format (
|
||||||
|
getCalEntriesUri, HttpUtility.UrlEncode (calid)) +
|
||||||
|
string.Format ("?orderBy=startTime&singleEvents=true&timeMin={0}&timeMax={1}&key=" + API_KEY,
|
||||||
|
HttpUtility.UrlEncode (mindate.ToString (dateFormat) + timeZone),
|
||||||
|
HttpUtility.UrlEncode (maxdate.ToString (dateFormat) + timeZone));
|
||||||
|
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (uri);
|
||||||
|
string cred = OAuth2.GetFreshGoogleCredential (upr);
|
||||||
|
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
|
||||||
|
webreq.Method = "GET";
|
||||||
|
webreq.ContentType = "application/http";
|
||||||
|
CalendarEntryList res = null;
|
||||||
|
try {
|
||||||
|
using (WebResponse resp = webreq.GetResponse ()) {
|
||||||
|
using (Stream respstream = resp.GetResponseStream ()) {
|
||||||
|
using (StreamReader readresp = new StreamReader (respstream, Encoding.UTF8)) {
|
||||||
|
responseStr = readresp.ReadToEnd ();
|
||||||
|
try {
|
||||||
|
res = JsonConvert.DeserializeObject<CalendarEntryList> (responseStr);
|
||||||
|
} catch (JsonReaderException ex) {
|
||||||
|
respstream.Close ();
|
||||||
|
resp.Close ();
|
||||||
|
webreq.Abort ();
|
||||||
|
throw new GoogleErrorException(ex,responseStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
respstream.Close ();
|
||||||
|
}
|
||||||
|
resp.Close ();
|
||||||
|
}
|
||||||
|
} catch (WebException ex) {
|
||||||
|
webreq.Abort ();
|
||||||
|
throw new GoogleErrorException (ex);
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
web/Helpers/Google/Entity.cs
Normal file
48
web/Helpers/Google/Entity.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
//
|
||||||
|
// Entity.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 Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
public class Entity
|
||||||
|
{
|
||||||
|
public string ID;
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The type:
|
||||||
|
// AUTOMOBILE: A car or passenger vehicle.
|
||||||
|
// TRUCK: A truck or cargo vehicle.
|
||||||
|
// WATERCRAFT: A boat or other waterborne vehicle.
|
||||||
|
// PERSON: A person.
|
||||||
|
/// </summary>
|
||||||
|
public string Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// JsonReaderError.cs
|
// EntityQuery.cs
|
||||||
//
|
//
|
||||||
// Author:
|
// Author:
|
||||||
// Paul Schneider <paulschneider@free.fr>
|
// Paul Schneider <paulschneider@free.fr>
|
||||||
|
|
@ -18,14 +18,21 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Yavsc.Model.Google
|
using System;
|
||||||
|
using Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
{
|
{
|
||||||
public class JsonReaderError
|
|
||||||
{
|
public class EntityQuery {
|
||||||
public string Text { get; set; }
|
public string [] EntityIds;
|
||||||
public Exception Excepx { get; set; }
|
public string MinId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
65
web/Helpers/Google/MapTracks.cs
Normal file
65
web/Helpers/Google/MapTracks.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
//
|
||||||
|
// Google.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 Yavsc.Helpers;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
|
||||||
|
public class MapTracks:ApiClient {
|
||||||
|
protected static string googleMapTracksPath = "https://www.googleapis.com/tracks/v1/";
|
||||||
|
// entities/[create|list|delete]
|
||||||
|
// collections/[list|create|[add|remove]entities|delete]
|
||||||
|
// crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete
|
||||||
|
|
||||||
|
|
||||||
|
// entities/[create|list|delete]
|
||||||
|
// collections/[list|create|[add|remove]entities|delete]
|
||||||
|
// crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete
|
||||||
|
|
||||||
|
|
||||||
|
static string [] CreateEntity( Entity[] entities ) {
|
||||||
|
string [] ans = null;
|
||||||
|
using (SimpleJsonPostMethod< Entity[] ,string []> wr =
|
||||||
|
new SimpleJsonPostMethod< Entity[] ,string[]> (googleMapTracksPath + "entities/create"))
|
||||||
|
{
|
||||||
|
ans = wr.Invoke (entities);
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
static Entity[] ListEntities (EntityQuery eq)
|
||||||
|
{
|
||||||
|
Entity [] ans = null;
|
||||||
|
using (SimpleJsonPostMethod<EntityQuery,Entity[]> wr =
|
||||||
|
new SimpleJsonPostMethod<EntityQuery,Entity[]> (googleMapTracksPath + "entities/create"))
|
||||||
|
{
|
||||||
|
ans = wr.Invoke (eq);
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
217
web/Helpers/Google/OAuth2.cs
Normal file
217
web/Helpers/Google/OAuth2.cs
Normal file
|
|
@ -0,0 +1,217 @@
|
||||||
|
//
|
||||||
|
// OAuth2.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.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Yavsc.Model.Google;
|
||||||
|
using System.Web.Profile;
|
||||||
|
using System.Web;
|
||||||
|
using Yavsc.Model;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers.Google
|
||||||
|
{
|
||||||
|
|
||||||
|
public class PeopleApi: ApiClient
|
||||||
|
{
|
||||||
|
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
|
||||||
|
|
||||||
|
public static People GetMe (AuthToken gat)
|
||||||
|
{
|
||||||
|
People me;
|
||||||
|
HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me");
|
||||||
|
webreppro.ContentType = "application/http";
|
||||||
|
webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token);
|
||||||
|
webreppro.Method = "GET";
|
||||||
|
using (WebResponse proresp = webreppro.GetResponse ()) {
|
||||||
|
using (Stream prresponseStream = proresp.GetResponseStream ()) {
|
||||||
|
using (StreamReader readproresp = new StreamReader (prresponseStream, Encoding.UTF8)) {
|
||||||
|
string prresponseStr = readproresp.ReadToEnd ();
|
||||||
|
me = JsonConvert.DeserializeObject<People> (prresponseStr);
|
||||||
|
}
|
||||||
|
prresponseStream.Close ();
|
||||||
|
}
|
||||||
|
proresp.Close ();
|
||||||
|
}
|
||||||
|
webreppro.Abort ();
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OAuth2:ApiClient
|
||||||
|
{
|
||||||
|
protected static string tokenUri = "https://accounts.google.com/o/oauth2/token";
|
||||||
|
protected static string authUri = "https://accounts.google.com/o/oauth2/auth";
|
||||||
|
|
||||||
|
public string RedirectUri { get; set; }
|
||||||
|
|
||||||
|
public OAuth2 (string redirectUri)
|
||||||
|
{
|
||||||
|
RedirectUri = redirectUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login with Google
|
||||||
|
/// by redirecting the specified http web response bresp,
|
||||||
|
/// and using the specified session state.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bresp">Bresp.</param>
|
||||||
|
/// <param name="state">State.</param>
|
||||||
|
public void Login (HttpResponseBase bresp, string state)
|
||||||
|
{
|
||||||
|
string scope = string.Join ("%20", scopeOpenid);
|
||||||
|
|
||||||
|
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false",
|
||||||
|
CLIENT_ID, RedirectUri, scope, state);
|
||||||
|
GetAuthResponse (bresp, prms);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetCalAuth (HttpResponseBase bresp, string state)
|
||||||
|
{
|
||||||
|
string scope = string.Join ("%20", scopeOpenid);
|
||||||
|
scope = string.Join ("%20", scopeCalendar);
|
||||||
|
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false&access_type=offline",
|
||||||
|
CLIENT_ID, RedirectUri, scope, state);
|
||||||
|
GetAuthResponse (bresp, prms);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GetAuthResponse (HttpResponseBase bresp, string prms)
|
||||||
|
{
|
||||||
|
string cont = null;
|
||||||
|
WebRequest wr = WebRequest.Create (authUri + "?" + prms);
|
||||||
|
wr.Method = "GET";
|
||||||
|
using (
|
||||||
|
WebResponse response = wr.GetResponse ()) {
|
||||||
|
string resQuery = response.ResponseUri.Query;
|
||||||
|
cont = HttpUtility.ParseQueryString (resQuery) ["continue"];
|
||||||
|
response.Close ();
|
||||||
|
}
|
||||||
|
wr.Abort ();
|
||||||
|
bresp.Redirect (cont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the post data, from code given
|
||||||
|
/// by Google in the request parameters,
|
||||||
|
/// and using the given <c>redirectUri</c>.
|
||||||
|
/// This request body is used to get a new
|
||||||
|
/// OAuth2 token from Google, it is Url encoded.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The post data from code.</returns>
|
||||||
|
/// <param name="redirectUri">Redirect URI.</param>
|
||||||
|
/// <param name="code">Code.</param>
|
||||||
|
public static string TokenPostDataFromCode (string redirectUri, string code)
|
||||||
|
{
|
||||||
|
string postdata =
|
||||||
|
string.Format (
|
||||||
|
"redirect_uri={0}&client_id={1}&client_secret={2}&code={3}&grant_type=authorization_code",
|
||||||
|
HttpUtility.UrlEncode (redirectUri),
|
||||||
|
HttpUtility.UrlEncode (CLIENT_ID),
|
||||||
|
HttpUtility.UrlEncode (CLIENT_SECRET),
|
||||||
|
HttpUtility.UrlEncode (code));
|
||||||
|
return postdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthToken GetToken (HttpRequestBase rq, string state, out string message)
|
||||||
|
{
|
||||||
|
string code = OAuth2.GetCodeFromRequest (rq, state, out message);
|
||||||
|
string postdata = OAuth2.TokenPostDataFromCode (RedirectUri, code);
|
||||||
|
return GetTokenPosting (postdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Obsolete ("Use GetToken instead.")]
|
||||||
|
public static AuthToken GetTokenFromBody (string postdata)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static AuthToken GetTokenPosting (string postdata)
|
||||||
|
{
|
||||||
|
HttpWebRequest webreq = WebRequest.CreateHttp (tokenUri);
|
||||||
|
webreq.Method = "POST";
|
||||||
|
webreq.Accept = "application/json";
|
||||||
|
webreq.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
Byte[] bytes = System.Text.Encoding.UTF8.GetBytes (postdata);
|
||||||
|
webreq.ContentLength = bytes.Length;
|
||||||
|
|
||||||
|
using (Stream dataStream = webreq.GetRequestStream ()) {
|
||||||
|
dataStream.Write (bytes, 0, bytes.Length);
|
||||||
|
dataStream.Close ();
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthToken gat = null;
|
||||||
|
using (WebResponse response = webreq.GetResponse ()) {
|
||||||
|
using (Stream responseStream = response.GetResponseStream ()) {
|
||||||
|
using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8)) {
|
||||||
|
string responseStr = readStream.ReadToEnd ();
|
||||||
|
gat = JsonConvert.DeserializeObject<AuthToken> (responseStr);
|
||||||
|
readStream.Close ();
|
||||||
|
}
|
||||||
|
responseStream.Close ();
|
||||||
|
}
|
||||||
|
response.Close ();
|
||||||
|
}
|
||||||
|
webreq.Abort ();
|
||||||
|
return gat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetCodeFromRequest (HttpRequestBase rq, string state, out string message)
|
||||||
|
{
|
||||||
|
message = "";
|
||||||
|
string code = rq.Params ["code"];
|
||||||
|
string error = rq.Params ["error"];
|
||||||
|
if (error != null) {
|
||||||
|
message =
|
||||||
|
string.Format (LocalizedText.Google_error,
|
||||||
|
LocalizedText.ResourceManager.GetString (error));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
string rqstate = rq.Params ["state"];
|
||||||
|
if (state != null && string.Compare (rqstate, state) != 0) {
|
||||||
|
message =
|
||||||
|
LocalizedText.ResourceManager.GetString ("invalid request state");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetFreshGoogleCredential (ProfileBase pr)
|
||||||
|
{
|
||||||
|
string token = (string)pr.GetPropertyValue ("gtoken");
|
||||||
|
string token_type = (string)pr.GetPropertyValue ("gtokentype");
|
||||||
|
DateTime token_exp = (DateTime)pr.GetPropertyValue ("gtokenexpir");
|
||||||
|
if (token_exp < DateTime.Now) {
|
||||||
|
string refresh_token = (string)pr.GetPropertyValue ("grefreshtoken");
|
||||||
|
AuthToken gat = OAuth2.GetTokenPosting (
|
||||||
|
string.Format ("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}",
|
||||||
|
CLIENT_ID, CLIENT_SECRET, refresh_token));
|
||||||
|
token = gat.access_token;
|
||||||
|
pr.SetPropertyValue ("gtoken", token);
|
||||||
|
pr.Save ();
|
||||||
|
// ASSERT gat.token_type == pr.GetPropertyValue("token_type")
|
||||||
|
}
|
||||||
|
return token_type + " " + token;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
91
web/Helpers/SimpleJsonPostMethod.cs
Normal file
91
web/Helpers/SimpleJsonPostMethod.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
//
|
||||||
|
// PostJson.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.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Helpers
|
||||||
|
{
|
||||||
|
public class SimpleJsonPostMethod<TQuery,TAnswer>: IDisposable
|
||||||
|
{
|
||||||
|
internal HttpWebRequest request = null;
|
||||||
|
internal HttpWebRequest Request { get { return request; } }
|
||||||
|
|
||||||
|
string CharSet {
|
||||||
|
get { return Request.TransferEncoding; }
|
||||||
|
set { Request.TransferEncoding=value;}
|
||||||
|
}
|
||||||
|
string Method { get { return Request.Method; } }
|
||||||
|
|
||||||
|
public string Path {
|
||||||
|
get{ return Request.RequestUri.ToString(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCredential(string cred) {
|
||||||
|
Request.Headers.Add(HttpRequestHeader.Authorization,cred);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleJsonPostMethod (string pathToMethod)
|
||||||
|
{
|
||||||
|
// ASSERT Request == null
|
||||||
|
request = WebRequest.CreateHttp (pathToMethod);
|
||||||
|
|
||||||
|
Request.Method = "POST";
|
||||||
|
Request.Accept = "application/json";
|
||||||
|
Request.ContentType = "application/json";
|
||||||
|
Request.TransferEncoding = "UTF-8";
|
||||||
|
}
|
||||||
|
|
||||||
|
public TAnswer Invoke(TQuery query)
|
||||||
|
{
|
||||||
|
Byte[] bytes = System.Text.Encoding.UTF8.GetBytes (JsonConvert.SerializeObject(query));
|
||||||
|
Request.ContentLength = bytes.Length;
|
||||||
|
|
||||||
|
using (Stream dataStream = Request.GetRequestStream ()) {
|
||||||
|
dataStream.Write (bytes, 0, bytes.Length);
|
||||||
|
dataStream.Close ();
|
||||||
|
}
|
||||||
|
TAnswer ans = default (TAnswer);
|
||||||
|
using (WebResponse response = Request.GetResponse ()) {
|
||||||
|
using (Stream responseStream = response.GetResponseStream ()) {
|
||||||
|
using (StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8)) {
|
||||||
|
string responseStr = readStream.ReadToEnd ();
|
||||||
|
ans = JsonConvert.DeserializeObject<TAnswer> (responseStr);
|
||||||
|
readStream.Close ();
|
||||||
|
}
|
||||||
|
responseStream.Close ();
|
||||||
|
}
|
||||||
|
response.Close();
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IDisposable implementation
|
||||||
|
public void Dispose ()
|
||||||
|
{
|
||||||
|
if (Request != null) Request.Abort ();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@
|
||||||
</aside>
|
</aside>
|
||||||
<footer>
|
<footer>
|
||||||
<% foreach ( string link in Yavsc.ThanksHelper.Links()) { %>
|
<% foreach ( string link in Yavsc.ThanksHelper.Links()) { %>
|
||||||
<div><%= link %></div>
|
<%= link %>
|
||||||
<% } %>
|
<% } %>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
<%= Html.TextBox("BlogTitle") %>
|
<%= Html.TextBox("BlogTitle") %>
|
||||||
<%= Html.ValidationMessage("BlogTitle", "*") %></td></tr>
|
<%= Html.ValidationMessage("BlogTitle", "*") %></td></tr>
|
||||||
<tr><td align="right">
|
<tr><td align="right">
|
||||||
Avatar </td><td> <img class="avatar" src="<%=Model.avatar%>" alt=""/>
|
Avatar : "<%=Model.avatar%>" </td><td> <img class="avatar" src="<%=Model.avatar%>" alt=""/>
|
||||||
<input type="file" id="AvatarFile" name="AvatarFile"/>
|
<input type="file" id="AvatarFile" name="AvatarFile"/>
|
||||||
<%= Html.ValidationMessage("AvatarFile", "*") %></td></tr>
|
<%= Html.ValidationMessage("AvatarFile", "*") %></td></tr>
|
||||||
<tr><td align="right">
|
<tr><td align="right">
|
||||||
|
|
|
||||||
12
web/Views/Google/GoogleErrorMessage.aspx
Normal file
12
web/Views/Google/GoogleErrorMessage.aspx
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<%@ Page Title="Google error message" Language="C#" Inherits="System.Web.Mvc.ViewPage<GoogleErrorException>" MasterPageFile="~/Models/App.master" %>
|
||||||
|
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
||||||
|
|
||||||
|
<h2><%= Html.Encode(Model.Title)%></h2>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
|
<%= Html.Encode(Model.Content) %>
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
<%@ Page Title="Json reader error" Language="C#" Inherits="System.Web.Mvc.ViewPage<JsonReaderError>" MasterPageFile="~/Models/App.master" %>
|
|
||||||
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
|
|
||||||
|
|
||||||
<h2><%= Html.Encode(Model.Excepx.Message)%></h2>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
<code>
|
|
||||||
<%= Html.Encode(Model.Text) %>
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
</asp:Content>
|
|
||||||
|
|
||||||
|
|
@ -118,6 +118,7 @@
|
||||||
<Folder Include="Views\Google\" />
|
<Folder Include="Views\Google\" />
|
||||||
<Folder Include="Settings\" />
|
<Folder Include="Settings\" />
|
||||||
<Folder Include="Views\BackOffice\" />
|
<Folder Include="Views\BackOffice\" />
|
||||||
|
<Folder Include="Helpers\Google\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\HomeController.cs" />
|
<Compile Include="Controllers\HomeController.cs" />
|
||||||
|
|
@ -164,6 +165,13 @@
|
||||||
<Compile Include="Settings\ModulesConfigurationSection.cs" />
|
<Compile Include="Settings\ModulesConfigurationSection.cs" />
|
||||||
<Compile Include="Settings\ModuleConfigurationElementCollection.cs" />
|
<Compile Include="Settings\ModuleConfigurationElementCollection.cs" />
|
||||||
<Compile Include="Settings\ModuleConfigurationElement.cs" />
|
<Compile Include="Settings\ModuleConfigurationElement.cs" />
|
||||||
|
<Compile Include="Helpers\SimpleJsonPostMethod.cs" />
|
||||||
|
<Compile Include="Helpers\Google\Entity.cs" />
|
||||||
|
<Compile Include="Helpers\Google\MapTracks.cs" />
|
||||||
|
<Compile Include="Helpers\Google\OAuth2.cs" />
|
||||||
|
<Compile Include="Helpers\Google\EntityQuery.cs" />
|
||||||
|
<Compile Include="Helpers\Google\ApiClient.cs" />
|
||||||
|
<Compile Include="Helpers\Google\Calendar.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
|
|
@ -261,7 +269,6 @@
|
||||||
<Content Include="Views\FrontOffice\Index.aspx" />
|
<Content Include="Views\FrontOffice\Index.aspx" />
|
||||||
<Content Include="Views\BackOffice\Index.aspx" />
|
<Content Include="Views\BackOffice\Index.aspx" />
|
||||||
<Content Include="images\sign-in-with-google-s.png" />
|
<Content Include="images\sign-in-with-google-s.png" />
|
||||||
<Content Include="Views\Google\JsonReaderError.aspx" />
|
|
||||||
<Content Include="Scripts\jquery-2.1.3-vsdoc.js" />
|
<Content Include="Scripts\jquery-2.1.3-vsdoc.js" />
|
||||||
<Content Include="Scripts\jquery-2.1.3.js" />
|
<Content Include="Scripts\jquery-2.1.3.js" />
|
||||||
<Content Include="Scripts\jquery-2.1.3.min.js" />
|
<Content Include="Scripts\jquery-2.1.3.min.js" />
|
||||||
|
|
@ -621,6 +628,7 @@
|
||||||
<Content Include="Scripts\globalize\cultures\globalize.cultures.js" />
|
<Content Include="Scripts\globalize\cultures\globalize.cultures.js" />
|
||||||
<Content Include="Scripts\datepicker-en-GB.js" />
|
<Content Include="Scripts\datepicker-en-GB.js" />
|
||||||
<Content Include="Scripts\datepicker-fr.js" />
|
<Content Include="Scripts\datepicker-fr.js" />
|
||||||
|
<Content Include="Views\Google\GoogleErrorMessage.aspx" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
|
|
@ -637,14 +645,12 @@
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README" />
|
<None Include="README" />
|
||||||
<None Include="uninstdbws.sql" />
|
|
||||||
<None Include="templates\Estim.tt">
|
<None Include="templates\Estim.tt">
|
||||||
<Generator>TextTemplatingFilePreprocessor</Generator>
|
<Generator>TextTemplatingFilePreprocessor</Generator>
|
||||||
<LastGenOutput>Estim.cs</LastGenOutput>
|
<LastGenOutput>Estim.cs</LastGenOutput>
|
||||||
</None>
|
</None>
|
||||||
<None Include="install\instdb.sql" />
|
<None Include="install\instdb.sql" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="instdbws.sql" />
|
|
||||||
<None Include="Scripts\jquery-2.1.3.min.map" />
|
<None Include="Scripts\jquery-2.1.3.min.map" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -677,4 +683,8 @@
|
||||||
<Name>NpgsqlWorkflow</Name>
|
<Name>NpgsqlWorkflow</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="instdbws.sql" />
|
||||||
|
<EmbeddedResource Include="uninstdbws.sql" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
50
yavscModel/Google/GoogleErrorMessage.cs
Normal file
50
yavscModel/Google/GoogleErrorMessage.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
//
|
||||||
|
// JsonReaderError.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.Net;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Yavsc.Model.Google
|
||||||
|
{
|
||||||
|
public class GoogleErrorException : Exception
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Content { get; set; }
|
||||||
|
|
||||||
|
public GoogleErrorException (WebException ex) {
|
||||||
|
// ASSERT ex != null;
|
||||||
|
Title = ex.Message;
|
||||||
|
|
||||||
|
using (var stream = ex.Response.GetResponseStream())
|
||||||
|
using (var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
Content = reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public GoogleErrorException(JsonReaderException ex, string message) {
|
||||||
|
Content = message;
|
||||||
|
Title = ex.Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -22,12 +22,5 @@ namespace Yavsc.Model
|
||||||
void Uninstall(IDbConnection cnx,bool removeConfig);
|
void Uninstall(IDbConnection cnx,bool removeConfig);
|
||||||
void Initialize (string name, NameValueCollection config);
|
void Initialize (string name, NameValueCollection config);
|
||||||
}
|
}
|
||||||
public interface IRenderer {
|
|
||||||
// Should set ViewData["Message|Author|Body"]
|
|
||||||
object Get(Controller c);
|
|
||||||
string Template { get; }
|
|
||||||
string Name { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
37
yavscModel/IRenderer.cs
Normal file
37
yavscModel/IRenderer.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
//
|
||||||
|
// IRenderer.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.Configuration;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Data;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Yavsc.Model
|
||||||
|
{
|
||||||
|
public interface IRenderer {
|
||||||
|
// Should set ViewData["Message|Author|Body"]
|
||||||
|
// and return an ActionResult
|
||||||
|
object Get(Controller c);
|
||||||
|
string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
yavscModel/ITagHandler.cs
Normal file
41
yavscModel/ITagHandler.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
//
|
||||||
|
// ITagHandler.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.Configuration;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Data;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Yavsc.Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public interface ITagHandler {
|
||||||
|
// Should set ViewData["Tags"] with
|
||||||
|
// an array of rendered tags
|
||||||
|
|
||||||
|
void Backup();
|
||||||
|
void Restore();
|
||||||
|
void Invoke();
|
||||||
|
string Name { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
42
yavscModel/IViewRenderer.cs
Normal file
42
yavscModel/IViewRenderer.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// IViewRenderer.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.Configuration;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Data;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Yavsc.Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public interface IViewRenderer : IRenderer {
|
||||||
|
|
||||||
|
// IRenderer.Get() Should set ViewData["Message|Author|Body"]
|
||||||
|
// and return an ActionResult
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the template route part
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The template.</value>
|
||||||
|
string Template { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
54
yavscModel/ViewRenderer.cs
Normal file
54
yavscModel/ViewRenderer.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
//
|
||||||
|
// ViewRenderer.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.Configuration;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Data;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Yavsc.Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public abstract class ViewRenderer<T> : IViewRenderer {
|
||||||
|
#region IRenderer implementation
|
||||||
|
public object Get (Controller c)
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
public string Template {
|
||||||
|
get {
|
||||||
|
return "Tag.aspx";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string Name {
|
||||||
|
get {
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -37,6 +37,9 @@
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Web.ApplicationServices" />
|
<Reference Include="System.Web.ApplicationServices" />
|
||||||
<Reference Include="System.Web.Mvc" />
|
<Reference Include="System.Web.Mvc" />
|
||||||
|
<Reference Include="System.Net" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Net.Http.Formatting" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
@ -91,8 +94,12 @@
|
||||||
<Compile Include="Google\CalendarList.cs" />
|
<Compile Include="Google\CalendarList.cs" />
|
||||||
<Compile Include="Google\CalendarListEntry.cs" />
|
<Compile Include="Google\CalendarListEntry.cs" />
|
||||||
<Compile Include="Google\AskForADate.cs" />
|
<Compile Include="Google\AskForADate.cs" />
|
||||||
<Compile Include="Google\JsonReaderError.cs" />
|
|
||||||
<Compile Include="Google\CalendarEntryList.cs" />
|
<Compile Include="Google\CalendarEntryList.cs" />
|
||||||
|
<Compile Include="IRenderer.cs" />
|
||||||
|
<Compile Include="ITagHandler.cs" />
|
||||||
|
<Compile Include="IViewRenderer.cs" />
|
||||||
|
<Compile Include="ViewRenderer.cs" />
|
||||||
|
<Compile Include="Google\GoogleErrorMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue