Skip to content

Commit

Permalink
⬆️ Update web template to RC2
Browse files Browse the repository at this point in the history
This commit brings file content changes
to web template (starter web with individual
authorization (in aspnet/Templates convention)
including:
- namespace changes
- project structure changes
- RC2 related structure additions
- assets changes
- client side deps updates
- test coverage update/rewrite
- client side assets updates
- SQLite EF updates

The template now restores, builds and
runs fine.
There are some small fixes remaining for
this tempalte to be done but they will
be part of separte review PR
  • Loading branch information
peterblazejewicz committed May 14, 2016
1 parent e3859d0 commit 8facb9a
Show file tree
Hide file tree
Showing 67 changed files with 1,651 additions and 1,214 deletions.
18 changes: 10 additions & 8 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.fs.copyTpl(this.templatePath('appsettings.json'), this.applicationName + '/appsettings.json', this.templatedata);
this.fs.copyTpl(this.templatePath('bower.json'), this.applicationName + '/bower.json', this.templatedata);
this.fs.copyTpl(this.templatePath('package.json'), this.applicationName + '/package.json', this.templatedata);
this.fs.copyTpl(this.templatePath('Program.cs'), this.applicationName + '/Program.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('project.json'), this.applicationName + '/project.json', this.templatedata);
this.fs.copy(this.templatePath('README.md'), this.applicationName + '/README.md');
this.fs.copyTpl(this.templatePath('Startup.cs'), this.applicationName + '/Startup.cs', this.templatedata);
Expand All @@ -227,26 +228,27 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.fs.copyTpl(this.templatePath('Controllers/HomeController.cs'), this.applicationName + '/Controllers/HomeController.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Controllers/ManageController.cs'), this.applicationName + '/Controllers/ManageController.cs', this.templatedata);
// Migrations
this.fs.copyTpl(this.templatePath('Migrations/00000000000000_CreateIdentitySchema.Designer.cs'), this.applicationName + '/Migrations/00000000000000_CreateIdentitySchema.Designer.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Migrations/00000000000000_CreateIdentitySchema.cs'), this.applicationName + '/Migrations/00000000000000_CreateIdentitySchema.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Migrations/ApplicationDbContextModelSnapshot.cs'), this.applicationName + '/Migrations/ApplicationDbContextModelSnapshot.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs'), this.applicationName + '/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Data/Migrations/00000000000000_CreateIdentitySchema.cs'), this.applicationName + '/Data/Migrations/00000000000000_CreateIdentitySchema.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Data/Migrations/ApplicationDbContextModelSnapshot.cs'), this.applicationName + '/Data/Migrations/ApplicationDbContextModelSnapshot.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Data/ApplicationDbContext.cs'), this.applicationName + '/Data/ApplicationDbContext.cs', this.templatedata);
// Models
this.fs.copyTpl(this.templatePath('Models/ApplicationDbContext.cs'), this.applicationName + '/Models/ApplicationDbContext.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Models/ApplicationUser.cs'), this.applicationName + '/Models/ApplicationUser.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Models/AccountViewModels/**/*'), this.applicationName + '/Models/AccountViewModels', this.templatedata);
this.fs.copyTpl(this.templatePath('Models/ManageViewModels/**/*'), this.applicationName + '/Models/ManageViewModels', this.templatedata);
// Properties
this.fs.copyTpl(this.templatePath('Properties/**/*'), this.applicationName + '/Properties', this.templatedata);
// Services
this.fs.copyTpl(this.templatePath('Services/IEmailSender.cs'), this.applicationName + '/Services/IEmailSender.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Services/ISmsSender.cs'), this.applicationName + '/Services/ISmsSender.cs', this.templatedata);
this.fs.copyTpl(this.templatePath('Services/MessageServices.cs'), this.applicationName + '/Services/MessageServices.cs', this.templatedata);
// ViewModels
this.fs.copyTpl(this.templatePath('ViewModels/**/*'), this.applicationName + '/ViewModels', this.templatedata);
// Views
this.fs.copyTpl(this.templatePath('Views/**/*'), this.applicationName + '/Views', this.templatedata);

// wwwroot
// wwwroot - the content in the wwwroot does not include any direct references or imports
// So again it is copied 1-to-1 - but tests cover list of all files
this.fs.copy(this.templatePath('wwwroot/**/*'), this.applicationName + '/wwwroot');

this.fs.copy(this.templatePath('web.config'), this.applicationName + '/web.config');
// UI Component Overrides
// If the developer has placed anything in overrides/ui-module/project-type/**/* then use it
this.fs.copyTpl(this.templatePath('/../../overrides/' + this.ui + '/' + this.type + '/**/*'), this.applicationName + '/', this.templatedata);
Expand Down
45 changes: 23 additions & 22 deletions templates/projects/web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using <%= namespace %>.Models;
using <%= namespace %>.Models.AccountViewModels;
using <%= namespace %>.Services;
using <%= namespace %>.ViewModels.Account;

namespace <%= namespace %>.Controllers
{
Expand Down Expand Up @@ -90,8 +89,9 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl =
// GET: /Account/Register
[HttpGet]
[AllowAnonymous]
public IActionResult Register()
public IActionResult Register(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}

Expand All @@ -100,8 +100,9 @@ public IActionResult Register()
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model)
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
Expand All @@ -113,10 +114,10 @@ public async Task<IActionResult> Register(RegisterViewModel model)
//var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
//var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
//await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
// "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
// $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation(3, "User created a new account with password.");
return RedirectToAction(nameof(HomeController.Index), "Home");
return RedirectToLocal(returnUrl);
}
AddErrors(result);
}
Expand Down Expand Up @@ -146,15 +147,20 @@ public IActionResult ExternalLogin(string provider, string returnUrl = null)
// Request a redirect to the external login provider.
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
return Challenge(properties, provider);
}

//
// GET: /Account/ExternalLoginCallback
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
if (remoteError != null)
{
ModelState.AddModelError(string.Empty, $"Error from external provider: {remoteError}");
return View(nameof(Login));
}
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
Expand All @@ -181,7 +187,7 @@ public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
// If the user does not have an account, then ask the user to create an account.
ViewData["ReturnUrl"] = returnUrl;
ViewData["LoginProvider"] = info.LoginProvider;
var email = info.ExternalPrincipal.FindFirstValue(ClaimTypes.Email);
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email });
}
}
Expand All @@ -193,11 +199,6 @@ public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
[ValidateAntiForgeryToken]
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
{
if (User.IsSignedIn())
{
return RedirectToAction(nameof(ManageController.Index), "Manage");
}

if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
Expand Down Expand Up @@ -273,7 +274,7 @@ public async Task<IActionResult> ForgotPassword(ForgotPasswordViewModel model)
//var code = await _userManager.GeneratePasswordResetTokenAsync(user);
//var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
//await _emailSender.SendEmailAsync(model.Email, "Reset Password",
// "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
// $"Please reset your password by clicking here: <a href='{callbackUrl}'>link</a>");
//return View("ForgotPasswordConfirmation");
}

Expand Down Expand Up @@ -430,7 +431,7 @@ public async Task<IActionResult> VerifyCode(VerifyCodeViewModel model)
}
else
{
ModelState.AddModelError("", "Invalid code.");
ModelState.AddModelError(string.Empty, "Invalid code.");
return View(model);
}
}
Expand All @@ -445,9 +446,9 @@ private void AddErrors(IdentityResult result)
}
}

private async Task<ApplicationUser> GetCurrentUserAsync()
private Task<ApplicationUser> GetCurrentUserAsync()
{
return await _userManager.FindByIdAsync(HttpContext.User.GetUserId());
return _userManager.GetUserAsync(HttpContext.User);
}

private IActionResult RedirectToLocal(string returnUrl)
Expand Down
2 changes: 1 addition & 1 deletion templates/projects/web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace <%= namespace %>.Controllers
{
Expand Down
21 changes: 10 additions & 11 deletions templates/projects/web/Controllers/ManageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Claims;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using <%= namespace %>.Models;
using <%= namespace %>.Models.ManageViewModels;
using <%= namespace %>.Services;
using <%= namespace %>.ViewModels.Manage;

namespace <%= namespace %>.Controllers
{
Expand Down Expand Up @@ -174,7 +173,7 @@ public async Task<IActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel mo
}

//
// GET: /Manage/RemovePhoneNumber
// POST: /Manage/RemovePhoneNumber
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> RemovePhoneNumber()
Expand Down Expand Up @@ -292,8 +291,8 @@ public IActionResult LinkLogin(string provider)
{
// Request a redirect to the external login provider to link a login for the current user
var redirectUrl = Url.Action("LinkLoginCallback", "Manage");
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, User.GetUserId());
return new ChallengeResult(provider, properties);
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));
return Challenge(properties, provider);
}

//
Expand All @@ -306,7 +305,7 @@ public async Task<ActionResult> LinkLoginCallback()
{
return View("Error");
}
var info = await _signInManager.GetExternalLoginInfoAsync(User.GetUserId());
var info = await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user));
if (info == null)
{
return RedirectToAction(nameof(ManageLogins), new { Message = ManageMessageId.Error });
Expand Down Expand Up @@ -338,9 +337,9 @@ public enum ManageMessageId
Error
}

private async Task<ApplicationUser> GetCurrentUserAsync()
private Task<ApplicationUser> GetCurrentUserAsync()
{
return await _userManager.FindByIdAsync(HttpContext.User.GetUserId());
return _userManager.GetUserAsync(HttpContext.User);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;

namespace <%= namespace %>.Models
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using <%= namespace %>.Models;

namespace <%= namespace %>.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
}
Loading

0 comments on commit 8facb9a

Please sign in to comment.