Implémente un formulaire simple

de réservation d'un préstataire

* p8-av4.xxs.jpg:
* p8-av4.xxs.png: inutile

* NoLogin.master:
* Entity.cs:
* OAuth2.cs:
* ApiClient.cs:
* PeopleApi.cs:
* MapTracks.cs:
* SkillManager.cs:
* Skills.aspx:
* EntityQuery.cs:
* CalendarApi.cs:
* SimpleJsonPostMethod.cs:
* GoogleHelpers.cs:
* EventPub.aspx:
* GoogleController.cs:
* Notification.cs:
* UserSkills.aspx:
* BackOfficeController.cs:
* BackOfficeController.cs:
* Notification.cs:
* MessageWithPayLoad.cs:
* MessageWithPayloadResponse.cs: refabrication

* IContentProvider.cs:
* NpgsqlBlogProvider.cs: xml doc

* NpgsqlContentProvider.cs: implemente un listing des prestataire du
  code APE en base.

* NpgsqlSkillProvider.cs: implemente un listing des domaines de
  compétence du préstataire en base.

* XmlCatalogProvider.cs: Le catalogue de vente implémente mainenant
  l'interface d'un fournisseur de donnée comme les autres.
Il pourrait par exemple vouloir définir des activité et des
  compétences.
Pour l'instant, il n'est pas activé par la configuration, et reste le
  fournisseur du catalogue legacy (voir </FrontOffice/Catalog> ).

* FrontOfficeController.cs: format du code

* Global.asax.cs: Une route customisée pour le Front Office : /do
  (genre, ici, ça bouge.)

* activity.sql: implémente en base de donnée le modèle des activités
  et compétences,
ajoute aussi deux activités : l'edition logicielle et "Artiste"

* style.css: changement de mes images de fond ... tombées du camion de
  Xavier et onlinehome.us

* p8-av4.s.jpg: changement de taille

* AccountController.cs: Met le code MEA à "none" quand il est spécifié
  non disponible.

* BlogsController.cs: fixe un bug de l'edition d'un billet

* FrontOfficeController.cs: implemente le contrôle booking simple

* HomeController.cs: ajoute l'assemblage du catalog dans le listing
  dédié

* YavscAjaxHelper.cs: Implemente un outil de representation JSon des
  objets côté serveur

* parallax.js: deux fois plus de mouvement autout de x dans le
  parallax

* yavsc.rate.js: imlemente un callback JS pour le rating

* Activities.aspx: Des labels au formulaire de déclaration des
  activités

* Activity.ascx: un panneau activité descent

* Booking.aspx: implemente l'UI web du booking simple.

* EavyBooking.aspx: refabrication du booking lourd

* Index.aspx: supprime le panneau du tag Accueil, affiche les
  activités en cours du site (avec au moins un préstataire valide pour
  cette activité)

* Web.config: Implemente une cote utilisateur, par une nouvelle valeur
  de son profile (Rate).

* Yavsc.csproj: refabrique du code API Google, qui part dans le model.

* MarkdownDeep.dll: le tag <p> ne convenait pas, le remplacer par le
  tag <span> non plus.
Maintenant ça devrait être correct, c'est un div, mais que en cas de
  tag englobant non défini.

* BookingQuery.cs: Le booking lourd devient une commande basée sur des
  activités concernée par l'intervention

* ChangeLog: nettoyage

* CatalogProvider.cs: implemente l'interface d'un fournissseur de
  contenu

* PerformerProfile.cs: implemente le profile prestataire

* SimpleBookingQuery.cs: Les besoin sont exprimé sous forme d'un
  tableau de valeur du parametrage de la commande

* LocalizedText.resx:
* LocalizedText.fr.resx:
* LocalizedText.Designer.cs:
* LocalizedText.fr.Designer.cs: internationalisation

* Profile.cs: implemente un accès à l'id d'enregistrement Google GCM

* SkillEntity.cs: La compétence appartient à un domaine d'activité, on
  lui associe un et un seul code APE

* SkillProvider.cs: Fait chercher les compétences à partir d'un code
  activité

* WorkFlowManager.cs: implemente l'accès à la liste des préstataires
de telle activité

* YavscModel.csproj: refabrications

* Skills.sql: vient de passer dans activity.Sql

* T.cs: la traduction est faite plus simple à appeler (sans cast vers
  `string`).
This commit is contained in:
Paul Schneider 2015-11-28 18:34:52 +01:00
commit a99232ba2b
68 changed files with 1402 additions and 1534 deletions

View file

@ -1,78 +0,0 @@
//
// 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
{
/// <summary>
/// Google base API client.
/// This class implements the identification values for a Google Api,
/// and provides some scope values.
/// </summary>
public class ApiClient
{
/// <summary>
/// The CLIENT Id.
/// </summary>
public static string CLIENT_ID { get ; set ; }
/// <summary>
/// The CLIENt SECREt
/// </summary>
public static string CLIENT_SECRET { get ; set ; }
/// <summary>
/// The API KEY.
/// </summary>
public static string API_KEY { get ; set ; }
/* // 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";
*/
/// <summary>
/// The Map tracks scope .
/// </summary>
protected static string scopeTracks = "https://www.googleapis.com/auth/tracks";
/// <summary>
/// The calendar scope.
/// </summary>
protected static string scopeCalendar = "https://www.googleapis.com/auth/calendar";
/// <summary>
/// The scope openid.
/// </summary>
protected static string[] scopeOpenid = {
"openid",
"profile",
"email"
};
}
}

View file

@ -1,134 +0,0 @@
//
// 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;
using System.Runtime.Serialization.Json;
using Yavsc.Model;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google Calendar API client.
/// </summary>
public class CalendarApi : ApiClient
{
public CalendarApi(string apiKey)
{
API_KEY = apiKey;
}
/// <summary>
/// The get cal list URI.
/// </summary>
protected static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
/// <summary>
/// The get cal entries URI.
/// </summary>
protected static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
/// <summary>
/// The date format.
/// </summary>
private static string dateFormat = "yyyy-MM-ddTHH:mm:ss";
/// <summary>
/// The time zone. TODO Fixme with machine time zone
/// </summary>
private string timeZone = "+01:00";
/// <summary>
/// Gets the calendar list.
/// </summary>
/// <returns>The calendars.</returns>
/// <param name="cred">Cred.</param>
public CalendarList GetCalendars (string cred)
{
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 ()) {
res = (CalendarList) new DataContractJsonSerializer(typeof(CalendarList)).ReadObject (respstream);
}
resp.Close ();
}
webreq.Abort ();
return res;
}
/// <summary>
/// Gets a calendar.
/// </summary>
/// <returns>The calendar.</returns>
/// <param name="calid">Calid.</param>
/// <param name="mindate">Mindate.</param>
/// <param name="maxdate">Maxdate.</param>
/// <param name="upr">Upr.</param>
public CalendarEventList GetCalendar (string calid, DateTime mindate, DateTime maxdate,string cred)
{
if (string.IsNullOrWhiteSpace (calid))
throw new Exception ("the calendar identifier is not specified");
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);
webreq.Headers.Add (HttpRequestHeader.Authorization, cred);
webreq.Method = "GET";
webreq.ContentType = "application/http";
CalendarEventList res = null;
try {
using (WebResponse resp = webreq.GetResponse ()) {
using (Stream respstream = resp.GetResponseStream ()) {
try {
res = (CalendarEventList) new DataContractJsonSerializer(typeof(CalendarEventList)).ReadObject (respstream);
} catch (Exception ) {
respstream.Close ();
resp.Close ();
webreq.Abort ();
throw ;
}
}
resp.Close ();
}
} catch (WebException ) {
webreq.Abort ();
throw;
}
webreq.Abort ();
return res;
}
}
}

View file

@ -1,56 +0,0 @@
//
// 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
{
/// <summary>
/// Entity.
/// </summary>
public class Entity
{
/// <summary>
/// The I.
/// </summary>
public string ID;
/// <summary>
/// The name.
/// </summary>
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;
}
}

View file

@ -1,46 +0,0 @@
//
// EntityQuery.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
{
/// <summary>
/// Entity query.
/// </summary>
public class EntityQuery {
/// <summary>
/// The entity identifiers.
/// </summary>
public string [] EntityIds;
/// <summary>
/// The minimum identifier.
/// </summary>
public string MinId;
}
}

View file

@ -1,137 +0,0 @@
//
// GoogleHelpers.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// 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.Model.Google;
using System.Web.Profile;
using System.Configuration;
using System.Web;
using Yavsc.Model.Calendar;
using Yavsc.Model.Circles;
using System.Collections.Generic;
using System.Web.Security;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google helpers.
/// </summary>
public static class GoogleHelpers
{
/// <summary>
/// Gets the events.
/// </summary>
/// <returns>The events.</returns>
/// <param name="profile">Profile.</param>
/// <param name="mindate">Mindate.</param>
/// <param name="maxdate">Maxdate.</param>
public static CalendarEventList GetEvents(this ProfileBase profile, DateTime mindate, DateTime maxdate)
{
string gcalid = (string) profile.GetPropertyValue ("gcalid");
if (string.IsNullOrWhiteSpace (gcalid))
throw new ArgumentException ("NULL gcalid");
CalendarApi c = new CalendarApi (clientApiKey);
string creds = OAuth2.GetFreshGoogleCredential (profile);
return c.GetCalendar (gcalid, mindate, maxdate, creds);
}
/// <summary>
/// Gets the calendars.
/// </summary>
/// <returns>The calendars.</returns>
/// <param name="profile">Profile.</param>
public static CalendarList GetCalendars (this ProfileBase profile)
{
string cred = OAuth2.GetFreshGoogleCredential (profile);
CalendarApi c = new CalendarApi (clientApiKey);
return c.GetCalendars (cred);
}
private static string clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"];
private static string clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"];
private static string clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"];
/// <summary>
/// Login the specified response, state and callBack.
/// </summary>
/// <param name="response">Response.</param>
/// <param name="state">State.</param>
/// <param name="callBack">Call back.</param>
public static void Login(this HttpResponseBase response, string state, string callBack)
{
OAuth2 oa = new OAuth2 (callBack, clientId,clientSecret);
oa.Login (response, state);
}
/// <summary>
/// Cals the login.
/// </summary>
/// <param name="response">Response.</param>
/// <param name="state">State.</param>
/// <param name="callBack">Call back.</param>
public static void CalLogin(this HttpResponseBase response, string state, string callBack)
{
OAuth2 oa = new OAuth2 (callBack,clientId,clientSecret);
oa.GetCalendarScope (response, state);
}
/// <summary>
/// Creates the O auth2.
/// </summary>
/// <returns>The O auth2.</returns>
/// <param name="callBack">Call back.</param>
public static OAuth2 CreateOAuth2(string callBack)
{
return new OAuth2 (callBack,clientId,clientSecret);
}
/// <summary>
/// Notifies the event.
/// </summary>
/// <returns>The event.</returns>
/// <param name="evpub">Evpub.</param>
public static MessageWithPayloadResponse NotifyEvent(EventPub evpub) {
using (SimpleJsonPostMethod<MessageWithPayload<YaEvent>,MessageWithPayloadResponse> r =
new SimpleJsonPostMethod<MessageWithPayload<YaEvent>,MessageWithPayloadResponse>(
"https://gcm-http.googleapis.com/gcm/send")) {
var users = Circle.Union (evpub.CircleIds);
var regids = new List<string> ();
var to = new List<string> ();
foreach (var u in users) {
var p = ProfileBase.Create (u);
if (p != null) {
var regid = p.GetPropertyValue("gregid");
if (regid == null) {
var muser = Membership.GetUser (u);
to.Add (muser.Email);
}
else regids.Add ((string)regid);
}
}
if (regids.Count == 0)
throw new InvalidOperationException
("No recipient where found for this circle list");
var msg = new MessageWithPayload<YaEvent> () {
notification = new Notification() { title = evpub.Title, body = evpub.Description, icon = "event" },
data = new YaEvent[] { (YaEvent)evpub }, registration_ids = regids.ToArray() };
return r.Invoke (msg);
}
}
}
}

View file

@ -1,81 +0,0 @@
//
// 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
{
/// <summary>
/// Google Map tracks Api client.
/// </summary>
public class MapTracks:ApiClient {
/// <summary>
/// The google map tracks path (uri of the service).
/// </summary>
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
/// <summary>
/// Creates the entity.
/// </summary>
/// <returns>The entity.</returns>
/// <param name="entities">Entities.</param>
public 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;
}
/// <summary>
/// Lists the entities.
/// </summary>
/// <returns>The entities.</returns>
/// <param name="eq">Eq.</param>
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;
}
}
}

View file

@ -1,252 +0,0 @@
//
// 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;
using System.Runtime.Serialization.Json;
using Yavsc.Helpers.Google;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google O auth2 client.
/// </summary>
public class OAuth2 : ApiClient
{
/// <summary>
/// The URI used to get tokens.
/// </summary>
protected static string tokenUri = "https://accounts.google.com/o/oauth2/token";
/// <summary>
/// The URI used to get authorized to.
/// </summary>
protected static string authUri = "https://accounts.google.com/o/oauth2/auth";
/// <summary>
/// Gets or sets the redirect URI sent to Google.
/// </summary>
/// <value>The redirect URI.</value>
public string RedirectUri { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2"/> class.
/// </summary>
/// <param name="redirectUri">Redirect URI.</param>
/// <param name="clientId">Client identifier.</param>
/// <param name="clientSecret">Client secret.</param>
public OAuth2 (string redirectUri, string clientId, string clientSecret)
{
RedirectUri = redirectUri;
CLIENT_ID = clientId;
CLIENT_SECRET = clientSecret;
}
/// <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&approval_prompt=force",
CLIENT_ID, RedirectUri, scope, state);
GetAuthResponse (bresp, prms);
}
/// <summary>
/// Gets the cal authorization.
/// </summary>
/// <param name="bresp">Bresp.</param>
/// <param name="state">State.</param>
public void GetCalendarScope (HttpResponseBase bresp, string state)
{
string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=true&access_type=offline&approval_prompt=force",
CLIENT_ID, RedirectUri, scopeCalendar, 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;
}
/// <summary>
/// Gets the Google Authorization token.
/// </summary>
/// <returns>The token.</returns>
/// <param name="rq">Rq.</param>
/// <param name="state">State.</param>
/// <param name="message">Message.</param>
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);
}
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 ()) {
gat = (AuthToken)new DataContractJsonSerializer (typeof(AuthToken)).ReadObject (responseStream);
responseStream.Close ();
}
response.Close ();
}
webreq.Abort ();
return gat;
}
/// <summary>
/// Gets the code from the Google request.
/// </summary>
/// <returns>The code from request.</returns>
/// <param name="rq">Rq.</param>
/// <param name="state">State.</param>
/// <param name="message">Message.</param>
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;
}
/// <summary>
/// Invalid O auth2 refresh token.
/// </summary>
public class InvalidOAuth2RefreshToken: Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
/// </summary>
/// <param name="message">Message.</param>
public InvalidOAuth2RefreshToken(string message):base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Helpers.Google.OAuth2.InvalidOAuth2RefreshToken"/> class.
/// </summary>
/// <param name="message">Message.</param>
/// <param name="innerException">Inner exception.</param>
public InvalidOAuth2RefreshToken(string message,Exception innerException):base(message,innerException)
{
}
}
/// <summary>
/// Gets fresh google credential.
/// </summary>
/// <returns>The fresh google credential.</returns>
/// <param name="pr">Pr.</param>
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) {
object ort = pr.GetPropertyValue ("grefreshtoken");
if (ort is DBNull || string.IsNullOrWhiteSpace((string)ort)) {
throw new InvalidOAuth2RefreshToken ("Google");
}
string refresh_token = ort as string;
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("gtokentype")
}
return token_type + " " + token;
}
}
}

View file

@ -1,68 +0,0 @@
//
// PeopleApi.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// 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;
using System.Runtime.Serialization.Json;
using Yavsc.Helpers.Google;
namespace Yavsc.Helpers.Google
{
/// <summary>
/// Google People API.
/// </summary>
public class PeopleApi: ApiClient
{
private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people";
/// <summary>
/// Gets the People object associated to the given Google Access Token
/// </summary>
/// <returns>The me.</returns>
/// <param name="gat">The Google Access Token object <see cref="AuthToken"/> class.</param>
public static People GetMe (AuthToken gat)
{
People me;
DataContractJsonSerializer ppser = new DataContractJsonSerializer (typeof(People));
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 ()) {
me = (People)ppser.ReadObject (prresponseStream);
prresponseStream.Close ();
}
proresp.Close ();
}
webreppro.Abort ();
return me;
}
}
}

View file

@ -1,108 +0,0 @@
//
// 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 System.Runtime.Serialization.Json;
namespace Yavsc.Helpers
{
/// <summary>
/// Simple json post method.
/// </summary>
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; } }
/// <summary>
/// Gets the path.
/// </summary>
/// <value>The path.</value>
public string Path {
get{ return Request.RequestUri.ToString(); }
}
/// <summary>
/// Sets the credential.
/// </summary>
/// <param name="cred">Cred.</param>
public void SetCredential(string cred) {
Request.Headers.Set(HttpRequestHeader.Authorization,cred);
}
/// <summary>
/// Initializes a new instance of the Yavsc.Helpers.SimpleJsonPostMethod class.
/// </summary>
/// <param name="pathToMethod">Path to method.</param>
public SimpleJsonPostMethod (string pathToMethod)
{
// ASSERT Request == null
request = WebRequest.CreateHttp (pathToMethod);
Request.Method = "POST";
Request.Accept = "application/json";
Request.ContentType = "application/json";
Request.SendChunked = true;
Request.TransferEncoding = "UTF-8";
}
/// <summary>
/// Invoke the specified query.
/// </summary>
/// <param name="query">Query.</param>
public TAnswer Invoke(TQuery query)
{
DataContractJsonSerializer serquery = new DataContractJsonSerializer (typeof(TQuery));
DataContractJsonSerializer seransw = new DataContractJsonSerializer (typeof(TAnswer));
using (MemoryStream streamQuery = new MemoryStream ()) {
serquery.WriteObject (streamQuery, query);
}
TAnswer ans = default (TAnswer);
using (WebResponse response = Request.GetResponse ()) {
using (Stream responseStream = response.GetResponseStream ()) {
ans = (TAnswer) seransw.ReadObject(responseStream);
}
response.Close();
}
return ans;
}
#region IDisposable implementation
/// <summary>
/// Releases all resource used by the Yavsc.Helpers.SimpleJsonPostMethod object.
/// </summary>
public void Dispose ()
{
if (Request != null) Request.Abort ();
}
#endregion
}
}

View file

@ -33,10 +33,10 @@ namespace Yavsc.Helpers
/// </summary>
/// <param name="helper">Helper.</param>
/// <param name="text">Text.</param>
public static IHtmlString Translate(this HtmlHelper helper, string text)
public static IHtmlString Translate(this HtmlHelper helper, object text)
{
// Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
return new MvcHtmlString(helper.Encode(GetString(text)));
return new MvcHtmlString(helper.Encode(GetString((string)text)));
}
}

View file

@ -22,6 +22,9 @@ using System;
using System.Web.Mvc;
using System.Collections.Generic;
using Yavsc.Model.Messaging;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
namespace Yavsc.Helpers
{
@ -61,10 +64,36 @@ namespace Yavsc.Helpers
return "\"" + tmpstr + "\"";
return "'" + tmpstr + "'";
}
public static string JString(this AjaxHelper helper, object str)
/// <summary>
/// Js the son string.
/// </summary>
/// <returns>The son string.</returns>
/// <param name="helper">Helper.</param>
/// <param name="obj">Object.</param>
public static string JSonString(this AjaxHelper helper, object obj)
{
return QuoteJavascriptString (str);
string result = null;
DataContractJsonSerializer ser = new DataContractJsonSerializer (obj.GetType());
var e = Encoding.UTF8;
using (MemoryStream streamQuery = new MemoryStream ()) {
ser.WriteObject (streamQuery, obj);
streamQuery.Seek (0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader (streamQuery)) {
result = sr.ReadToEnd ();
}
}
return result;
}
/// <summary>
/// Js the string.
/// </summary>
/// <returns>The string.</returns>
/// <param name="helper">Helper.</param>
/// <param name="text">Text.</param>
public static string JString(this AjaxHelper helper, object text)
{
return QuoteJavascriptString ((string)text);
}
}
}