* minor changes (like an [em] BBcode)

* Trying to use OAuth2 Google Login
This commit is contained in:
Paul Schneider 2014-12-09 01:59:38 +01:00
commit 3f41636719
32 changed files with 16285 additions and 119 deletions

View file

@ -0,0 +1,44 @@
using System;
using Yavsc;
using SalesCatalog;
using SalesCatalog.Model;
using System.Web.Routing;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Web.Http;
using System.Net.Http;
using System.Web;
using System.Linq;
using System.IO;
using System.Net;
using WorkFlowProvider;
using System.Web.Security;
using Yavsc.Model.WorkFlow;
using System.Reflection;
using System.Collections.Generic;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Controllers;
using Yavsc.Formatters;
using System.Text;
using System.Web.Profile;
namespace Yavsc.ApiControllers
{
public class FormInputValue: IValueProvider<T>
{
#region IValueProvider implementation
public T GetValue ()
{
throw new NotImplementedException ();
}
#endregion
}
}

View file

@ -21,6 +21,7 @@ using Yavsc.Controllers;
using Yavsc.Formatters;
using System.Text;
using System.Web.Profile;
using System.Collections.Specialized;
namespace Yavsc.ApiControllers
{
@ -70,8 +71,13 @@ namespace Yavsc.ApiControllers
return result;
}
*/
/*
[Authorize]
public IOrderInfo Order()
{
}
*/
[Authorize]
[HttpGet]
/// <summary>

View file

@ -11,6 +11,7 @@ using System.Collections.Generic;
using Yavsc.Model.WorkFlow;
using WorkFlowProvider;
using System.Web.Security;
using System.Threading;
namespace Yavsc.Controllers
{
@ -20,6 +21,9 @@ namespace Yavsc.Controllers
/// </summary>
public class FrontOfficeController : Controller
{
/*
*/
[Authorize]
public ActionResult Estimates ()
{

View file

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
using System.Web.Mvc;
using System.Configuration;
using System.Threading.Tasks;
using System.Text;
using Mono.Security.Protocol.Tls;
using System.Net;
using System.IO;
using Yavsc.Model;
namespace Yavsc.Controllers
{
public class GoogleController : Controller
{
string API_KEY="AIzaSyBV_LQHb22nGgjNvFzZwnQHjao3Q7IewRw";
string CLIENT_ID="325408689282-6bekh7p3guj4k0f3301a6frf025cnrk1.apps.googleusercontent.com";
string CLIENT_SECRET="MaxYcvJJCs2gDGvaELZbzwfL";
string [] SCOPES = {
"profile",
"email"
} ;
string getTokenUrl = "https://accounts.google.com/o/oauth2/token";
// "https://www.googleapis.com/oauth2/v3/token";https://accounts.google.com/o/oauth2/token
string getCodeUrl = "https://accounts.google.com/o/oauth2/auth";
public void Login()
{
Random rand = new Random ();
string state = "security_token"+rand.Next (100000).ToString()+rand.Next (100000).ToString();
Session ["state"] = state;
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/Auth";
string prms = String.Format("response_type=code&" +
"client_id={0}&" +
"redirect_uri={1}&" +
"scope={2}&" +
"state={3}&" +
"access_type=offline&" +
"include_granted_scopes=false",
CLIENT_ID,
redirectUri,
string.Join("%20",SCOPES),
state
);
WebRequest wr = WebRequest.Create(getCodeUrl+"?"+prms);
wr.Method = "GET";
// Get the response.
try {
WebResponse response = wr.GetResponse();
string resQuery = response.ResponseUri.Query;
string cont = HttpUtility.ParseQueryString(resQuery)["continue"];
Response.Redirect (cont);
}
catch (WebException we) {
Response.Redirect(we.Response.ResponseUri.AbsoluteUri);
}
}
public void Auth() {
string redirectUri = Request.Url.Scheme + "://" + Request.Url.Authority + "/Google/Code";
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;
}
string state = Request.Params ["state"];
if (state!=null && string.Compare((string)Session ["state"],state)!=0) {
ViewData ["Message"] =
LocalizedText.ResourceManager.GetString("invalid request state");
return;
}
HttpWebRequest webreq = WebRequest.CreateHttp(getTokenUrl);
webreq.Method = "POST";
webreq.ContentType = "application/x-www-form-urlencoded";
webreq.SendChunked = true;
string postData = String.Format("code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type=authorization_code",
code,
CLIENT_ID,
CLIENT_SECRET,
redirectUri);
Encoding encr = new UTF8Encoding();
Byte[] bytes = encr.GetBytes(postData);
webreq.ContentLength = bytes.Length;
using (Stream dataStream = webreq.GetRequestStream()) {
dataStream.Write(bytes,0,bytes.Length);
dataStream.Close();
}
try {
WebResponse response = webreq.GetResponse();
string resQuery = response.ResponseUri.Query;
string cont = HttpUtility.ParseQueryString(resQuery)["continue"];
Response.Redirect (cont);
}
catch (WebException wex) {
Response.Redirect(wex.Response.ResponseUri.AbsoluteUri);
}
}
public void Code()
{
}
}
}

View file

@ -0,0 +1,37 @@
using System;
using Yavsc;
using SalesCatalog;
using SalesCatalog.Model;
using System.Web.Routing;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Web.Http;
using System.Net.Http;
using System.Web;
using System.Linq;
using System.IO;
using System.Net;
using WorkFlowProvider;
using System.Web.Security;
using Yavsc.Model.WorkFlow;
using System.Reflection;
using System.Collections.Generic;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Controllers;
using Yavsc.Formatters;
using System.Text;
using System.Web.Profile;
namespace Yavsc.ApiControllers
{
public interface IOrderInfo
{
DateTime Creation { get; set; }
string Status { get; set; }
long OrderId { get; set; }
FormInputValue [] Details { get; set; }
}
}

View file

@ -0,0 +1,34 @@
using System;
using Yavsc;
using SalesCatalog;
using SalesCatalog.Model;
using System.Web.Routing;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Web.Http;
using System.Net.Http;
using System.Web;
using System.Linq;
using System.IO;
using System.Net;
using WorkFlowProvider;
using System.Web.Security;
using Yavsc.Model.WorkFlow;
using System.Reflection;
using System.Collections.Generic;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Controllers;
using Yavsc.Formatters;
using System.Text;
using System.Web.Profile;
namespace Yavsc.ApiControllers
{
interface IValueProvider<T>
{
T GetValue();
}
}

View file

@ -298,6 +298,7 @@ namespace Yavsc.Helpers
parser = new BBCodeParser (new[] {
new BBTag ("b", "<b>", "</b>"),
new BBTag ("i", "<span style=\"font-style:italic;\">", "</span>"),
new BBTag ("em", "<em>", "</em>"),
new BBTag ("u", "<span style=\"text-decoration:underline;\">", "</span>"),
new BBTag ("code", "<span class=\"code\">", "</span>"),
new BBTag ("img", "<img src=\"${content}\" alt=\"${alt}\" style=\"${style}\" />", "", false, true, new BBAttribute ("alt", ""), new BBAttribute("alt","alt"), new BBAttribute ("style", "style")),

6632
web/Scripts/jquery-2.1.1-vsdoc.js vendored Normal file

File diff suppressed because it is too large Load diff

9190
web/Scripts/jquery-2.1.1.js vendored Normal file

File diff suppressed because it is too large Load diff

4
web/Scripts/jquery-2.1.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
<%@ Page Title="Login" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<%= Html.ValidationSummary("Ouverture de session avec OpenID") %>
<% using(Html.BeginForm("OpenIDLogOn", "Account")) %>
<% { %>
<label for="loginIdentifier"/>
<%= Html.TextBox( "loginIdentifier" ) %>
<%= Html.ValidationMessage("loginIdentifier", "*") %>
<% } %>
</asp:Content>

View file

@ -0,0 +1,6 @@
<%@ Page Title="Catalog" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
AccessToken : <%= Session["AccessToken"] %>
Target in error : <%= ViewData["TargetNameError"] %>
</asp:Content>

View file

@ -0,0 +1,5 @@
<%@ Page Title="Catalog" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
</asp:Content>

View file

@ -0,0 +1,5 @@
<%@ Page Title="Catalog" Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
</asp:Content>

View file

@ -25,15 +25,39 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<section name="catalog" type="SalesCatalog.Configuration.CatalogProvidersConfigurationSection, SalesCatalog" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
<section name="workflow" type="Yavsc.Model.WorkFlow.Configuration.WorkflowConfiguration, YavscModel" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
</sectionGroup>
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
</sectionGroup>
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
</sectionGroup>
</configSections>
<!-- <runtime>
<runtime>
<!--
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="3.5.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime> -->
-->
<!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). -->
<legacyHMACWarning enabled="0" />
<!-- When targeting ASP.NET MVC 3, this assemblyBinding makes MVC 1 and 2 references relink
to MVC 3 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it.
-->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
<!--
Set compilation debug="true" to insert debugging
@ -108,7 +132,7 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
</httpModules>
<httpRuntime maxRequestLength="52428800" />
<trace enabled="false" localOnly="true" pageOutput="false" requestLimit="10" traceMode="SortByTime" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />
<membership defaultProvider="NpgsqlMembershipProvider" userIsOnlineTimeWindow="1">
<providers>
<clear />
@ -207,12 +231,55 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
</providers>
</catalog>
<system.net>
<!-- not supported: <defaultProxy enabled="true" /> -->
<settings>
<!-- This setting causes .NET to check certificate revocation lists (CRL)
before trusting HTTPS certificates. But this setting tends to not
be allowed in shared hosting environments. -->
<!--<servicePointManager checkCertificateRevocationList="true"/>-->
</settings>
<mailSettings>
<smtp deliveryMethod="network" from="paulschneider@free.fr">
<network host="smtp.free.fr" port="25" defaultCredentials="false" />
</smtp>
</mailSettings>
</system.net>
<dotNetOpenAuth>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<!-- Uncomment to enable communication with localhost (should generally not activate in production!) -->
<!--<add name="localhost" />-->
</whitelistHosts>
</untrustedWebRequest>
</messaging>
<!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
<reporting enabled="true" />
<!-- This is an optional configuration section where aspects of dotnetopenauth can be customized. -->
<!-- For a complete set of configuration options see http://www.dotnetopenauth.net/developers/code-snippets/configuration-options/ -->
<openid>
<relyingParty>
<security requireSsl="false">
<!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. -->
<!--<trustedProviders rejectAssertionsFromUntrustedProviders="true">
<add endpoint="https://www.google.com/accounts/o8/ud" />
</trustedProviders>-->
</security>
<behaviors>
<!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
with OPs that use Attribute Exchange (in various formats). -->
<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId.RelyingParty" />
</behaviors>
</relyingParty>
</openid>
</dotNetOpenAuth>
<uri>
<!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
which is necessary for OpenID urls with unicode characters in the domain/host name.
It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
<idn enabled="All" />
<iriParsing enabled="true" />
</uri>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="30" name=".ASPXFORM$" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Index.aspx" enableCrossAppRedirects="false" />
</authentication>
@ -227,7 +294,7 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<add key="Name" value="Psc" />
<add key="DefaultAvatar" value="/images/noavatar.png;image/png" />
<add key="RegistrationMessage" value="/RegistrationMail.txt" />
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
</configuration>

View file

@ -75,8 +75,6 @@
<Reference Include="Mono.Posix" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.ServiceModel.Routing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
@ -92,6 +90,12 @@
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Net" />
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
@ -119,6 +123,7 @@
<Folder Include="Formatters\" />
<Folder Include="install\" />
<Folder Include="App_GlobalResources\" />
<Folder Include="Views\Google\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
@ -158,6 +163,10 @@
<Compile Include="Formatters\EstimToPdfFormatter.cs" />
<Compile Include="Formatters\SimpleFormatter.cs" />
<Compile Include="ValidateAjaxAttribute.cs" />
<Compile Include="Controllers\IOrderInfo.cs" />
<Compile Include="Controllers\FormInputValue.cs" />
<Compile Include="Controllers\IValueProvider.cs" />
<Compile Include="Controllers\GoogleController.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Web.config" />
@ -241,6 +250,14 @@
<Content Include="RegistrationMail.txt" />
<Content Include="instdbws.sql" />
<Content Include="Views\FrontOffice\Writting.ascx" />
<Content Include="packages.config" />
<Content Include="Views\Account\OpenIDLogOn.aspx" />
<Content Include="Views\Google\Calendar.aspx" />
<Content Include="Views\Google\Login.aspx" />
<Content Include="Scripts\jquery-2.1.1-vsdoc.js" />
<Content Include="Scripts\jquery-2.1.1.js" />
<Content Include="Scripts\jquery-2.1.1.min.js" />
<Content Include="Views\Google\Auth.aspx" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
@ -264,6 +281,7 @@
<LastGenOutput>Estim.cs</LastGenOutput>
</None>
<None Include="install\instdb.sql" />
<None Include="Scripts\jquery-2.1.1.min.map" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NpgsqlMRPProviders\NpgsqlMRPProviders.csproj">

View file

@ -249,6 +249,7 @@ CREATE TABLE profiledata
wicketcode character varying(5),
iban character varying(33),
bic character varying(15),
gcode character varying(512),
CONSTRAINT fkprofiles2 FOREIGN KEY (uniqueid)
REFERENCES profiles (uniqueid) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE

5
web/packages.config Normal file
View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="jQuery" version="2.1.1" targetFramework="net40" />
<package id="log4net" version="2.0.3" targetFramework="net40" />
</packages>

3
web/web.config Normal file
View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>