* minor changes (like an [em] BBcode)
* Trying to use OAuth2 Google Login
This commit is contained in:
parent
d1f76f4902
commit
3f41636719
32 changed files with 16285 additions and 119 deletions
44
web/Controllers/FormInputValue.cs
Normal file
44
web/Controllers/FormInputValue.cs
Normal 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
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 ()
|
||||
{
|
||||
|
|
|
|||
120
web/Controllers/GoogleController.cs
Normal file
120
web/Controllers/GoogleController.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
web/Controllers/IOrderInfo.cs
Normal file
37
web/Controllers/IOrderInfo.cs
Normal 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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
34
web/Controllers/IValueProvider.cs
Normal file
34
web/Controllers/IValueProvider.cs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue