-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring and updates on core modules.
- Loading branch information
Showing
148 changed files
with
7,954 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Web.Hosting; | ||
using Frapid.ApplicationState.Cache; | ||
|
||
namespace Frapid.Account | ||
{ | ||
public class Configuration | ||
{ | ||
private const string Path = "~/Catalogs/{0}/Areas/Frapid.Account/"; | ||
|
||
public static string GetOverridePath() | ||
{ | ||
string catalog = AppUsers.GetCatalog(); | ||
string path = HostingEnvironment.MapPath(string.Format(CultureInfo.InvariantCulture, Path, catalog)); | ||
|
||
return path != null && !Directory.Exists(path) ? string.Empty : path; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Frapid.Web/Areas/Frapid.Account/Controllers/Backend/ConfigurationProfileController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Web.Mvc; | ||
using Frapid.Dashboard.Controllers; | ||
|
||
namespace Frapid.Account.Controllers.Backend | ||
{ | ||
public class ConfigurationProfileController : DashboardController | ||
{ | ||
[Route("dashboard/account/configuration-profile")] | ||
[Authorize] | ||
public ActionResult Index() | ||
{ | ||
return this.FrapidView(this.GetRazorView<AreaRegistration>("ConfigurationProfile/Index.cshtml")); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Frapid.Web/Areas/Frapid.Account/Controllers/Backend/EmailTemplateController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.IO; | ||
using System.Text; | ||
using System.Web.Mvc; | ||
using Frapid.Account.ViewModels; | ||
using Frapid.Dashboard.Controllers; | ||
|
||
namespace Frapid.Account.Controllers.Backend | ||
{ | ||
public class EmailTemplateController : DashboardController | ||
{ | ||
[Route("dashboard/account/email-templates/{file}")] | ||
[Authorize] | ||
public ActionResult Index(string file) | ||
{ | ||
string contents = this.GetContents(file); | ||
|
||
if (string.IsNullOrWhiteSpace(contents)) | ||
{ | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
var model = new Template { Contents = contents, Title = file + ".html" }; | ||
return this.FrapidView(this.GetRazorView<AreaRegistration>("EmailTemplate/Index.cshtml"), model); | ||
} | ||
|
||
[Route("dashboard/account/email-templates")] | ||
[Authorize] | ||
[HttpPost] | ||
public ActionResult Save(Template model) | ||
{ | ||
this.SetContents(model.Title, model.Contents); | ||
return Json("OK"); | ||
} | ||
|
||
private string GetContents(string file) | ||
{ | ||
string path = Configuration.GetOverridePath() + "/EmailTemplates/" + file + ".html"; | ||
return System.IO.File.Exists(path) ? System.IO.File.ReadAllText(path, Encoding.UTF8) : string.Empty; | ||
} | ||
|
||
private void SetContents(string file, string contents) | ||
{ | ||
string path = Configuration.GetOverridePath() + "/EmailTemplates/" + file; | ||
if (System.IO.File.Exists(path)) | ||
{ | ||
System.IO.File.WriteAllText(path, contents, Encoding.UTF8); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Frapid.Web/Areas/Frapid.Account/Controllers/Backend/RoleController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Web.Mvc; | ||
using Frapid.Dashboard.Controllers; | ||
|
||
namespace Frapid.Account.Controllers.Backend | ||
{ | ||
public class RoleController : DashboardController | ||
{ | ||
[Route("dashboard/account/roles")] | ||
[Authorize] | ||
public ActionResult Index() | ||
{ | ||
return this.FrapidView(this.GetRazorView<AreaRegistration>("Role/Index.cshtml")); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Frapid.Web/Areas/Frapid.Account/Controllers/Backend/UserController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Web.Mvc; | ||
using Frapid.Dashboard.Controllers; | ||
|
||
namespace Frapid.Account.Controllers.Backend | ||
{ | ||
public class UserController : DashboardController | ||
{ | ||
[Route("dashboard/account/user-management")] | ||
[Authorize] | ||
public ActionResult Index() | ||
{ | ||
return this.FrapidView(this.GetRazorView<AreaRegistration>("User/Index.cshtml")); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Frapid.Web/Areas/Frapid.Account/Controllers/FacebookController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using Frapid.Account.InputModels; | ||
using Frapid.Account.RemoteAuthentication; | ||
using Npgsql; | ||
|
||
namespace Frapid.Account.Controllers | ||
{ | ||
public class FacebookController : BaseAuthenticationController | ||
{ | ||
[Route("account/facebook/sign-in")] | ||
[HttpPost] | ||
[AllowAnonymous] | ||
public async Task<ActionResult> FacebookSignInAsync(FacebookAccount account) | ||
{ | ||
var auth = new FacebookAuthentication(); | ||
try | ||
{ | ||
var result = | ||
await auth.AuthenticateAsync(account, this.RemoteUser); | ||
return this.OnAuthenticated(result); | ||
} | ||
catch (NpgsqlException) | ||
{ | ||
return this.Json("Access is denied."); | ||
} | ||
} | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/Frapid.Web/Areas/Frapid.Account/Controllers/Frontend/ResetController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using Frapid.Account.InputModels; | ||
using Frapid.Account.Messaging; | ||
using Frapid.Account.ViewModels; | ||
using Frapid.WebsiteBuilder.Controllers; | ||
using Registration = Frapid.Account.DAL.Registration; | ||
|
||
namespace Frapid.Account.Controllers.Frontend | ||
{ | ||
public class ResetController : WebsiteBuilderController | ||
{ | ||
[Route("account/reset")] | ||
[AllowAnonymous] | ||
public ActionResult Index() | ||
{ | ||
return this.View(this.GetRazorView<AreaRegistration>("Reset/Index.cshtml"), new Reset()); | ||
} | ||
|
||
[Route("account/reset")] | ||
[AllowAnonymous] | ||
[HttpPost] | ||
public async Task<ActionResult> IndexAsync(ResetInfo model) | ||
{ | ||
var token = this.Session["Token"]; | ||
if (token == null) | ||
{ | ||
return this.Redirect("/"); | ||
} | ||
|
||
if (model.Token != token.ToString()) | ||
{ | ||
return this.Redirect("/"); | ||
} | ||
|
||
model.Browser = this.RemoteUser.Browser; | ||
model.IpAddress = this.RemoteUser.IpAddress; | ||
|
||
if (DAL.Reset.HasActiveResetRequest(model.Email)) | ||
{ | ||
return this.Json(true); | ||
} | ||
|
||
var result = DAL.Reset.Request(model); | ||
|
||
if (result.UserId <= 0) | ||
{ | ||
return this.Redirect("/"); | ||
} | ||
|
||
|
||
var email = new ResetEmail(result); | ||
await email.SendAsync(); | ||
return this.Json(true); | ||
} | ||
|
||
[Route("account/reset/validate-email")] | ||
[HttpPost] | ||
[AllowAnonymous] | ||
public ActionResult ValidateEmail(string email) | ||
{ | ||
Thread.Sleep(1000); | ||
return string.IsNullOrWhiteSpace(email) ? this.Json(true) : this.Json(!Registration.HasAccount(email)); | ||
} | ||
|
||
[Route("account/reset/email-sent")] | ||
[AllowAnonymous] | ||
public ActionResult ResetEmailSent() | ||
{ | ||
return this.View(this.GetRazorView<AreaRegistration>("Reset/ResetEmailSent.cshtml")); | ||
} | ||
|
||
[Route("account/reset/confirm")] | ||
[AllowAnonymous] | ||
public ActionResult Do(string token) | ||
{ | ||
if (string.IsNullOrWhiteSpace(token)) | ||
{ | ||
return this.Redirect("/site/404"); | ||
} | ||
|
||
var reset = DAL.Reset.GetIfActive(token); | ||
|
||
if (reset == null) | ||
{ | ||
return this.Redirect("/site/404"); | ||
} | ||
|
||
return this.View(this.GetRazorView<AreaRegistration>("Reset/Do.cshtml")); | ||
} | ||
|
||
[Route("account/reset/confirm")] | ||
[HttpPost] | ||
[AllowAnonymous] | ||
public ActionResult Do() | ||
{ | ||
string token = this.Request.QueryString["token"]; | ||
string password = this.Request.QueryString["password"]; | ||
|
||
if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(password)) | ||
{ | ||
return this.Json(false); | ||
} | ||
|
||
var reset = DAL.Reset.GetIfActive(token); | ||
if (reset != null) | ||
{ | ||
DAL.Reset.CompleteReset(token, password); | ||
return this.Json(true); | ||
} | ||
|
||
return this.Json(false); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Frapid.Web/Areas/Frapid.Account/Controllers/Frontend/SignupController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using AutoMapper; | ||
using Frapid.Account.DTO; | ||
using Frapid.Account.Exceptions; | ||
using Frapid.Account.Messaging; | ||
using Frapid.Framework.Extensions; | ||
using Frapid.WebsiteBuilder.Controllers; | ||
using Registration = Frapid.Account.ViewModels.Registration; | ||
|
||
namespace Frapid.Account.Controllers | ||
{ | ||
public class SignUpController : WebsiteBuilderController | ||
{ | ||
[Route("account/sign-up")] | ||
[AllowAnonymous] | ||
public ActionResult Index() | ||
{ | ||
var profile = DAL.Configuration.GetActiveProfile(); | ||
|
||
if (!profile.AllowRegistration || User.Identity.IsAuthenticated) | ||
{ | ||
return Redirect("/dashboard"); | ||
} | ||
|
||
return View(GetRazorView<AreaRegistration>("SignUp/Index.cshtml")); | ||
} | ||
|
||
[Route("account/sign-up/confirmation-email-sent")] | ||
[AllowAnonymous] | ||
public ActionResult EmailSent() | ||
{ | ||
return View(GetRazorView<AreaRegistration>("SignUp/EmailSent.cshtml")); | ||
} | ||
|
||
[Route("account/sign-up/confirm")] | ||
[AllowAnonymous] | ||
public async Task<ActionResult> ConfirmAsync(string token) | ||
{ | ||
Guid id = token.To<Guid>(); | ||
|
||
if (!DAL.Registration.ConfirmRegistration(id)) | ||
{ | ||
return View(GetRazorView<AreaRegistration>("SignUp/InvalidToken.cshtml")); | ||
} | ||
|
||
DTO.Registration registration = DAL.Registration.Get(id); | ||
WelcomeEmail email = new WelcomeEmail(registration); | ||
await email.SendAsync(); | ||
|
||
return View(GetRazorView<AreaRegistration>("SignUp/Welcome.cshtml")); | ||
} | ||
|
||
[Route("account/sign-up/validate-email")] | ||
[HttpPost] | ||
[AllowAnonymous] | ||
public ActionResult ValidateEmail(string email) | ||
{ | ||
Thread.Sleep(1000); | ||
return string.IsNullOrWhiteSpace(email) ? Json(true) : Json(!DAL.Registration.EmailExists(email)); | ||
} | ||
|
||
[Route("account/sign-up")] | ||
[HttpPost] | ||
[AllowAnonymous] | ||
public async Task<ActionResult> PostAsync(Registration model) | ||
{ | ||
if (model.Password != model.ConfirmPassword) | ||
{ | ||
throw new PasswordConfirmException("Passwords do not match."); | ||
} | ||
|
||
if (model.Email != model.ConfirmEmail) | ||
{ | ||
throw new PasswordConfirmException("Passwords do not match."); | ||
} | ||
|
||
model.Browser = this.RemoteUser.Browser; | ||
model.IpAddress = this.RemoteUser.IpAddress; | ||
|
||
Mapper.CreateMap<Registration, DTO.Registration>(); | ||
var registration = Mapper.Map<DTO.Registration>(model); | ||
string registrationId = DAL.Registration.Register(registration).ToString(); | ||
|
||
if (string.IsNullOrWhiteSpace(registrationId)) | ||
{ | ||
return Json(false); | ||
} | ||
|
||
var email = new SignUpEmail(registration, registrationId); | ||
await email.SendAsync(); | ||
return Json(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.