Fichiers manquant au dernier commit

vnext
Paul Schneider 9 years ago
parent e8bf2dd8fa
commit d8965ed526
17 changed files with 1412 additions and 0 deletions

@ -0,0 +1,53 @@
# Fonctionalités
# Une publication des talent du site
Des notions de *préstataire*, d'*activité* et de *compténces*
dirigent maintenant le "link juice":
Sont publiées en home page les descriptions en temps réel des activités soutenues par au mois un préstataire enregistré, ayant déclaré son statut de préstataire par un choix parmis les activités configurée par l'administration du site.
Le prestataire peut détailler ses compétences, en leur donnant une côte de départ, qui sera modifiée par les clients de ce prestataire, une fois le service rendu.
# Une reservation de préstataire
Le préstataire peut renseigner un identifiant de calendrier Google.
Dans ce cas, à la proposition de la reservation de ses services,
on peut verifier (à l'aide d'un algorythme à rendre modulaire)
sa disponibilité et présenter au client un peu plus de confiance
dans le succès de sa demande de reservation.
La fiche prestataire presente aussi, le cas échéant, un lien vers son blog (à l'existence de billets publiques).
Le processus de reservation d'un préstataire peut être conduit par un utilisateur anonyme (non enregistré sur le site) jusqu'à la validation de son panier de commandes.
## Un blog spot
On peut poster des billets, avec une mise en forme stockée à la Markdown en base de donnée,
en WYSIWYG depuis l'interface Web grâce à un fork de hallo.js .
La syntaxe a été etendue pour pouvoir publier, en tant qu'objet du document, des vidéos et fichiers audio.
On peut attacher toute sorte de document à chacun des billets.
# Un système de facturation
Pour l'instant, il est réduit au minimum : un édition d'un devis, qui à la publicaton en LaTeX ou Pdf est présenté comme une facture.
## Peut-être à desactiver ? à rendre optionnel au niveau administratif et utilisateur : le systeme de fichiers utilisateur
Tout utilisateur enregistré dispose aussi du moyen de publier des applications de son choix, via son espace de fichiers perso ou ses billet de blog.
# La conformité légale
Hors mis les mentions légales concernant la responsabilité du site,
un système d'avertissement unique par utilisateur à été mis en place.
Il a été mis en oeuvre pour prévenir tout nouvel utilisateur, qu'en parcourant ce site,
il accèpte le stockage de données persistantes sur son ordinateur, appélées "cookies"
destinées à lui faciliter son expérience du site ...
Il reste à prévenir de l'utilisation des liens vers les réseaux sociaux (pour l'instant, seulement Google Plus).

@ -0,0 +1,23 @@
<%@ Page Language="C#" Title="Performers" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<PerformerAvailability>>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<% foreach (var available in Model) { %>
<div class="usercard">
<%= Html.Partial("Performer", available.Profile ) %><br>
<% if (available.DateAvailable) {
%>
<%= Html.Translate("ThisPerformerGivesAccessToHisCalendarAndSeemsToBeAvailable") %>
<%
}
else if (available.Profile.HasCalendar()) {
%>
<%= Html.Translate("ThisPerformerGivesAccessToHisCalendarAndItAppearsHeShouldNotBeAvailable") %>
<%
} else {
%>
<%= Html.Translate("ThisPerformerDoesntGiveAccessToHisCalendar") %>
<%
} %></div><% } %>
</asp:Content>

@ -0,0 +1,9 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Activity>" %>
<div>
<div data-type="background" data-speed="10" style="width:100%; height:10em; background: url(<%=Ajax.JString(Model.Photo)%>) 50% 50% repeat fixed;" >
</div>
<h1><a href="<%= Url.RouteUrl("FrontOffice", new { action="Booking", MEACode=Model.Id }) %>">
<%=Html.Encode(Model.Title)%></a></h1>
<p>
<%=Html.Markdown(Model.Comment)%>
</p></div>

@ -0,0 +1,82 @@
//
// PerformerAvailability.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.RolesAndMembers;
using Yavsc.Model.Skill;
using System.Web.Security;
using System.Web.Profile;
using System.Collections.Generic;
using Yavsc.Model;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Yavsc.Model.Google.Api;
using Yavsc.Model.WorkFlow;
namespace Yavsc.Model.FrontOffice
{
/// <summary>
/// Performer availability.
/// </summary>
public class PerformerAvailability : UserNameBase {
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FrontOffice.PerformerAvailability"/> class.
/// </summary>
/// <param name="profile">Profile.</param>
/// <param name="userName">User name.</param>
/// <param name="date">Date.</param>
/// <param name="available">If set to <c>true</c> available.</param>
public PerformerAvailability(PerformerProfile profile,
string userName, DateTime date, bool available) {
DateAvailable = available;
PerformanceDate = date;
UserName = userName;
preformerProfile = profile;
}
PerformerProfile preformerProfile = null;
/// <summary>
/// Gets the profile.
/// </summary>
/// <value>The profile.</value>
public PerformerProfile Profile
{
get {
return preformerProfile;
}
}
/// <summary>
/// Gets or sets the performance date.
/// </summary>
/// <value>The performance date.</value>
public DateTime PerformanceDate { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Yavsc.Model.FrontOffice.PerformerAvailability"/> date available.
/// </summary>
/// <value><c>true</c> if date available; otherwise, <c>false</c>.</value>
public bool DateAvailable { get; set; }
}
}

@ -0,0 +1,98 @@
//
// 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 System.Web.Profile;
using Yavsc.Model.Google;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using System.Configuration;
namespace Yavsc.Model.Google.Api
{
/// <summary>
/// Google base API client.
/// This class implements the identification values for a Google Api,
/// and provides some scope values.
/// </summary>
public class ApiClient
{
private static string clientId=null;
private static string clientSecret=null;
private static string clientApiKey=null;
/// <summary>
/// The CLIENT Id.
/// </summary>
public static string CLIENT_ID {
get {
if (clientId==null)
clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"];
return clientId;
}
}
/// <summary>
/// The CLIENt SECREt
/// </summary>
public static string CLIENT_SECRET {get {
if (clientSecret==null)
clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"];
return clientSecret;
}}
/// <summary>
/// The API KEY.
/// </summary>
public static string API_KEY {get {
if (clientApiKey==null)
clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"];
return clientApiKey;
}}
/* // 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"
};
}
}

@ -0,0 +1,132 @@
//
// 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 System.Web.Profile;
using Yavsc.Model.Google;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using System.Web;
using Yavsc.Model;
using System.Runtime.Serialization.Json;
namespace Yavsc.Model.Google.Api
{
/// <summary>
/// Google Calendar API client.
/// </summary>
public class CalendarApi : ApiClient
{
public CalendarApi()
{
}
/// <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 event list, between the given dates.
/// </summary>
/// <returns>The calendar.</returns>
/// <param name="calid">Calendar identifier.</param>
/// <param name="mindate">Mindate.</param>
/// <param name="maxdate">Maxdate.</param>
/// <param name="cred">credential string.</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;
}
}
}

@ -0,0 +1,55 @@
//
// 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 System.Web.Profile;
using Yavsc.Model.Google;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace Yavsc.Model.Google.Api
{
/// <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;
}
}

@ -0,0 +1,45 @@
//
// 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 System.Web.Profile;
using Yavsc.Model.Google;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace Yavsc.Model.Google.Api
{
/// <summary>
/// Entity query.
/// </summary>
public class EntityQuery {
/// <summary>
/// The entity identifiers.
/// </summary>
public string [] EntityIds;
/// <summary>
/// The minimum identifier.
/// </summary>
public string MinId;
}
}

@ -0,0 +1,136 @@
//
// 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;
using Yavsc.Model.Google.Api.Messaging;
namespace Yavsc.Model.Google.Api
{
/// <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 ();
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 ();
return c.GetCalendars (cred);
}
/// <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);
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);
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);
}
/// <summary>
/// Notifies the event.
/// </summary>
/// <returns>The event.</returns>
/// <param name="evpub">Evpub.</param>
public static MessageWithPayloadResponse NotifyEvent(EventPub evpub) {
using (var 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);
}
}
}
}

@ -0,0 +1,80 @@
//
// 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 System.Web.Profile;
using Yavsc.Model.Google;
using System.Net;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace Yavsc.Model.Google.Api
{
/// <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;
}
}
}

@ -0,0 +1,98 @@
//
// MessageWithPayLoad.cs
//
// Author:
// paul <>
//
// Copyright (c) 2015 paul
//
// 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.Web.Mvc;
namespace Yavsc.Model.Google.Api.Messaging
{
// https://gcm-http.googleapis.com/gcm/send
/// <summary>
/// Message with payload.
/// </summary>
public class MessageWithPayload<T> {
/// <summary>
/// To.
/// </summary>
public string to;
/// <summary>
/// The registration identifiers.
/// </summary>
public string [] registration_ids;
/// <summary>
/// The data.
/// </summary>
public T[] data ;
/// <summary>
/// The notification.
/// </summary>
public Notification notification;
/// <summary>
/// The collapse key.
/// </summary>
public string collapse_key; // in order to collapse ...
/// <summary>
/// The priority.
/// </summary>
public int priority; // between 0 and 10, 10 is the lowest!
/// <summary>
/// The content available.
/// </summary>
public bool content_available;
/// <summary>
/// The delay while idle.
/// </summary>
public bool delay_while_idle;
/// <summary>
/// The time to live.
/// </summary>
public int time_to_live; // seconds
/// <summary>
/// The name of the restricted package.
/// </summary>
public string restricted_package_name;
/// <summary>
/// The dry run.
/// </summary>
public bool dry_run;
/// <summary>
/// Validate the specified modelState.
/// </summary>
/// <param name="modelState">Model state.</param>
public void Validate(ModelStateDictionary modelState) {
if (to==null && registration_ids == null) {
modelState.AddModelError ("to", "One of \"to\" or \"registration_ids\" parameters must be specified");
modelState.AddModelError ("registration_ids", "*");
modelState.AddModelError ("to", "*");
}
if (notification == null && data == null) {
modelState.AddModelError ("notification", "At least one of \"notification\" or \"data\" parameters must be specified");
modelState.AddModelError ("data", "*");
}
if (notification != null) {
if (notification.icon == null)
modelState.AddModelError ("notification.icon", "please, specify an icon resoure name");
if (notification.title == null)
modelState.AddModelError ("notification.title", "please, specify a title");
}
}
}
}

@ -0,0 +1,71 @@
//
// MessageWithPayloadResponse.cs
//
// Author:
// paul <paul@pschneider.fr>
//
// Copyright (c) 2015 paul
//
// 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;
namespace Yavsc.Model.Google.Api.Messaging
{
// https://gcm-http.googleapis.com/gcm/send
/// <summary>
/// Message with payload response.
/// </summary>
public class MessageWithPayloadResponse {
/// <summary>
/// The multicast identifier.
/// </summary>
public int multicast_id;
/// <summary>
/// The success count.
/// </summary>
public int success;
/// <summary>
/// The failure count.
/// </summary>
public int failure;
/// <summary>
/// The canonical identifiers... ?!?
/// </summary>
public int canonical_ids;
/// <summary>
/// Detailled result.
/// </summary>
public class Result {
/// <summary>
/// The message identifier.
/// </summary>
public string message_id;
/// <summary>
/// The registration identifier.
/// </summary>
public string registration_id;
/// <summary>
/// The error.
/// </summary>
public string error;
}
/// <summary>
/// The results.
/// </summary>
public Result [] results;
}
}

@ -0,0 +1,62 @@
//
// Notification.cs
//
// Author:
// paul <>
//
// Copyright (c) 2015 paul
//
// 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;
namespace Yavsc.Model.Google.Api.Messaging
{
/// <summary>
/// Notification.
/// </summary>
public class Notification {
/// <summary>
/// The title.
/// </summary>
public string title;
/// <summary>
/// The body.
/// </summary>
public string body;
/// <summary>
/// The icon.
/// </summary>
public string icon;
/// <summary>
/// The sound.
/// </summary>
public string sound;
/// <summary>
/// The tag.
/// </summary>
public string tag;
/// <summary>
/// The color.
/// </summary>
public string color;
/// <summary>
/// The click action.
/// </summary>
public string click_action;
}
// https://gcm-http.googleapis.com/gcm/send
}

@ -0,0 +1,249 @@
//
// 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;
namespace Yavsc.Model.Google.Api
{
/// <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)
{
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&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;
}
}
}

@ -0,0 +1,67 @@
//
// 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;
namespace Yavsc.Model.Google.Api
{
/// <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;
}
}
}

@ -0,0 +1,108 @@
//
// 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.Model
{
/// <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 = (HttpWebRequest) WebRequest.Create (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 (Stream streamQuery = request.GetRequestStream()) {
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
}
}

@ -0,0 +1,44 @@
//
// SkillRating.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;
namespace Yavsc.Model.Skill
{
/// <summary>
/// Skill rating.
/// </summary>
public class SkillRating : IRating {
/// <summary>
/// Gets or sets the skill identifier.
/// </summary>
/// <value>The skill identifier.</value>
public long Id { get;set ; }
/// <summary>
/// Gets or sets the rate.
/// </summary>
/// <value>The rate.</value>
public int Rate { get; set; }
}
}
Loading…