Skip to content

Commit

Permalink
Login, Register
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertBodner committed Dec 24, 2015
1 parent 73b82f5 commit 5021a61
Show file tree
Hide file tree
Showing 38 changed files with 28,127 additions and 2,619 deletions.
34 changes: 32 additions & 2 deletions src/Example.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using WaCore.Data;
using WaCore.Entities.Core;
using WaCore.Web;

namespace Example.Web
Expand All @@ -19,7 +23,7 @@ public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
//.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);


Expand All @@ -41,16 +45,42 @@ public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<WaCoreDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));


services.ConfigureWaCore(Configuration);

services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<WaCoreDbContext, Guid>()
.AddDefaultTokenProviders();

}

public IConfigurationRoot Configuration { get; set; }

public void Configure(IApplicationBuilder app)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();

if (env.IsEnvironment("Development"))
{
//app.UseBrowserLink();

app.UseDeveloperExceptionPage();

//app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
//app.UseStatusCodePagesWithReExecute("/error/{0}");
app.UseStatusCodePagesWithReExecute("/error/{0}");
}

// Add cookie-based authentication to the request pipeline.
app.UseIdentity();

// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
Expand Down
12 changes: 1 addition & 11 deletions src/Example.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<title>Hello on the HOME page</title>
</head>
<body>
<div>
yeah, you are at home!!!
yeah, you are at home!!!!!!!!!!!!
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions src/Example.Web/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
81 changes: 81 additions & 0 deletions src/Example.Web/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WaCore Example</title>

@*<environment names="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/lib/bootstrap-touch-carousel/dist/css/bootstrap-touch-carousel.css" />
<link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.0.0/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="hidden" asp-fallback-test-property="visibility" asp-fallback-test-value="hidden" />
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap-touch-carousel/0.8.0/css/bootstrap-touch-carousel.css"
asp-fallback-href="~/lib/bootstrap-touch-carousel/css/bootstrap-touch-carousel.css"
asp-fallback-test-class="carousel-caption" asp-fallback-test-property="display" asp-fallback-test-value="none" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</environment>*@
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-controller="Home" asp-action="Index" class="navbar-brand">WebApplication7</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-controller="Home" asp-action="About">About</a></li>
<li><a asp-controller="Home" asp-action="Contact">Contact</a></li>
</ul>
@await Html.PartialAsync("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; 2015 - WaCore Example</p>
</footer>
</div>

@*<environment names="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="~/lib/hammer.js/hammer.js"></script>
<script src="~/lib/bootstrap-touch-carousel/dist/js/bootstrap-touch-carousel.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
</environment>
<environment names="Staging,Production">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.0.0/bootstrap.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/hammer.js/2.0.4/hammer.min.js"
asp-fallback-src="~/lib/hammer.js/hammer.js"
asp-fallback-test="window.Hammer">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap-touch-carousel/0.8.0/js/bootstrap-touch-carousel.js"
asp-fallback-src="~/lib/bootstrap-touch-carousel/dist/js/bootstrap-touch-carousel.js"
asp-fallback-test="window.Hammer && window.Hammer.Instance">
</script>
<script src="~/js/site.js" asp-append-version="true"></script>
</environment>*@

@RenderSection("scripts", required: false)
</body>
</html>
20 changes: 20 additions & 0 deletions src/Example.Web/Views/Shared/_LoginPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@using System.Security.Claims

@if (User.Identity.IsAuthenticated)
{
<form asp-controller="Account" asp-action="LogOff" method="post" id="logoutForm" class="navbar-right">
<ul class="nav navbar-nav navbar-right">
<li>
<a asp-controller="Manage" asp-action="Index" title="Manage">Hello @User.GetUserName()!</a>
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
</form>
}
else
{
<ul class="nav navbar-nav navbar-right">
<li><a asp-controller="Account" asp-action="Register">Register</a></li>
<li><a asp-controller="Account" asp-action="Login">Log in</a></li>
</ul>
}
14 changes: 14 additions & 0 deletions src/Example.Web/Views/Shared/_ValidationScriptsPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<environment names="Development">
<script src="~/lib/jquery-validation/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment names="Staging,Production">
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"
asp-fallback-src="~/lib/jquery-validation/jquery.validate.js"
asp-fallback-test="window.jquery && window.jquery.validator">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
asp-fallback-test="window.jquery && window.jquery.validator && window.jquery.validator.unobtrusive">
</script>
</environment>
61 changes: 47 additions & 14 deletions src/Example.Web/Views/WaCore/Account/Login.cshtml
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
@{
Layout = null;
}
@using System.Threading.Tasks
@using WaCore.Web.ViewModels.Accounts
@model WaCore.Web.ViewModels.Accounts.LoginViewModel

<!DOCTYPE html>

<html>
<head>
<title>Hello on the LOGIN page</title>
</head>
<body>
<div>
yeah, you are at login!!!
<h2>Login</h2>
<div class="row">
<div class="col-md-8">
<section>
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
<h4>Use a local account to log in.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="Password" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Password" class="form-control" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
<input asp-for="RememberMe" />
<label asp-for="RememberMe"></label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="submit" class="btn btn-default">Log in</button>
</div>
</div>
<p>
<a asp-action="Register">Register as a new user?</a>
</p>
<p>
<a asp-action="ForgotPassword">Forgot your password?</a>
</p>
</form>
</section>
</div>
</body>
</html>
</div>
43 changes: 43 additions & 0 deletions src/Example.Web/Views/WaCore/Account/Register.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@using System.Threading.Tasks
@using WaCore.Web.ViewModels.Accounts
@model WaCore.Web.ViewModels.Accounts.RegisterViewModel
@{
}

<h2>Register.</h2>

<form asp-controller="Account" asp-action="Register" method="post" class="form-horizontal" role="form">
<h4>Create a new account.</h4>
<hr />
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="Password" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Password" class="form-control" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="ConfirmPassword" class="form-control" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="submit" class="btn btn-default">Register</button>
</div>
</div>
</form>

@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
1 change: 1 addition & 0 deletions src/Example.Web/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
3 changes: 3 additions & 0 deletions src/Example.Web/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
7 changes: 7 additions & 0 deletions src/Example.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=WaCoreExample;Trusted_Connection=True;"
}
}
}
12 changes: 10 additions & 2 deletions src/Example.Web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta8",
"Microsoft.AspNet.Http.Abstractions": "1.0.0-beta8",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"WaCore.Contracts": "1.0.0-*",
"WaCore.Web": "1.0.0-*"
"WaCore.Web": "1.0.0-*",
"WaCore.Entities": "1.0.0-*",
"WaCore.Bl": "1.0.0-*",
"WaCore.Data": "1.0.0-*"
},

"commands": {
Expand All @@ -26,5 +33,6 @@
"publishExclude": [
"**.user",
"**.vspscc"
]
],
"userSecretsId": "aspnet5-Example.Web-20151223095404"
}
25 changes: 25 additions & 0 deletions src/WaCore.Bl/Services/Account/AccountResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WaCore.Contracts.Bl.Services.Account;

namespace WaCore.Bl.Services.Account
{
public class AccountResult : IAccountResult
{
public static AccountResult Success()
{
return new AccountResult();
}

public AccountResult(List<string> errors = null)
{
Errors = errors ?? new List<string>();
}

public IEnumerable<string> Errors { get; }

public bool Succeeded => !Errors.Any();
}
}
Loading

0 comments on commit 5021a61

Please sign in to comment.