Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,5 @@ paket-files/
/src/LetsDisc.EntityFrameworkCore/Migrations/20180628102141_LetsDisc-v1.cs
/src/LetsDisc.EntityFrameworkCore/Migrations/20180628102141_LetsDisc-v1.Designer.cs
**/appsettings.json
**/yarn.lock
**/package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<RegisterOutput> Register(RegisterInput input)
input.EmailAddress,
input.UserName,
input.Password,
true // Assumed email address is always confirmed. Change this if you want to implement email confirmation.
false
);

var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync<bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin);
Expand Down
24 changes: 23 additions & 1 deletion src/LetsDisc.Core/Authorization/Users/UserRegistrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
using Abp.UI;
using LetsDisc.Authorization.Roles;
using LetsDisc.MultiTenancy;
using Abp.Net.Mail;
using LetsDisc;
using System.Text.Encodings.Web;
using System.Text;
using Microsoft.AspNetCore.WebUtilities;

namespace LetsDisc.Authorization.Users
{
Expand All @@ -22,17 +27,21 @@ public class UserRegistrationManager : DomainService
private readonly UserManager _userManager;
private readonly RoleManager _roleManager;
private readonly IPasswordHasher<User> _passwordHasher;
private readonly IEmailSender _emailSender;


public UserRegistrationManager(
TenantManager tenantManager,
UserManager userManager,
RoleManager roleManager,
IPasswordHasher<User> passwordHasher)
IPasswordHasher<User> passwordHasher,
IEmailSender emailSender)
{
_tenantManager = tenantManager;
_userManager = userManager;
_roleManager = roleManager;
_passwordHasher = passwordHasher;
_emailSender = emailSender;

AbpSession = NullAbpSession.Instance;
}
Expand Down Expand Up @@ -65,6 +74,19 @@ public async Task<User> RegisterAsync(string name, string surname, string emailA
}

CheckErrors(await _userManager.CreateAsync(user));
var emailConfirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);
user.EmailConfirmationCode = emailConfirmationToken;

// The angular app is converting '+' to space, and thus it was giving Invalid Token Problem.
// Encoding it to Base 64 and then decoding while checking the token
byte[] tokenGeneratedBytes = Encoding.UTF8.GetBytes(emailConfirmationToken);
var codeEncoded = WebEncoders.Base64UrlEncode(tokenGeneratedBytes);

var url = String.Format("{0}/account/confirmemail?userId={1}&code={2}", LetsDiscConsts.BaseUrl, user.Id, codeEncoded);

await _emailSender.SendAsync(emailAddress, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(url)}'>clicking here</a>.");

await CurrentUnitOfWork.SaveChangesAsync();

return user;
Expand Down
4 changes: 3 additions & 1 deletion src/LetsDisc.Core/Configuration/AppSettingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Abp.Configuration;
using Abp.Net.Mail;
using Abp.Zero.Configuration;
using LetsDisc.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -28,7 +29,8 @@ public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefi
new SettingDefinition(EmailSettingNames.Smtp.EnableSsl, "true"),
new SettingDefinition(EmailSettingNames.Smtp.UseDefaultCredentials, "false"),
new SettingDefinition(EmailSettingNames.Smtp.UserName, _appConfiguration["Authentication:Mailjet:UserName"]),
new SettingDefinition(EmailSettingNames.Smtp.Password, _appConfiguration["Authentication:Mailjet:Password"])
new SettingDefinition(EmailSettingNames.Smtp.Password, _appConfiguration["Authentication:Mailjet:Password"]),
new SettingDefinition(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin, "true")
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/LetsDisc.Core/LetsDiscConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class LetsDiscConsts
//https://aspnetboilerplate.com/Pages/Documents/Zero/Tenant-Management

public const bool MultiTenancyEnabled = false;
public const string BaseUrl = "http://localhost:4200";
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;

Expand Down
37 changes: 30 additions & 7 deletions src/LetsDisc.Web.Core/Controllers/TokenAuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
using Microsoft.AspNetCore.Authorization;
using System.Threading;
using Abp.Net.Mail;
using Abp.Domain.Entities;
using System.Web;
using Microsoft.AspNetCore.WebUtilities;
using System.Text;

namespace LetsDisc.Controllers
{
Expand Down Expand Up @@ -87,13 +91,6 @@ public async Task<AuthenticateResultModel> Authenticate([FromBody] AuthenticateM

var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity));

/*await _emailSender.SendAsync(
to: "[email protected]",
subject: "You have a new task!",
body: $"A new task is assigned for you: ",
isBodyHtml: true
);*/

return new AuthenticateResultModel
{
AccessToken = accessToken,
Expand Down Expand Up @@ -358,6 +355,32 @@ private async Task<User> RegisterForExternalLogin(List<Claim> claims)
return user;
}

[HttpPost]
public async Task<long> ConfirmEmail(long id, string code)
{
var user = await _userManager.GetUserByIdAsync(id);
if (user == null)
{
throw new EntityNotFoundException(typeof(User), id);
}

// The angular app is converting '+' to space, and thus it was giving Invalid Token Problem.
// Encoding it to Base 64 and then decoding here

var codeDecodedBytes = WebEncoders.Base64UrlDecode(code);
var decodedCode = Encoding.UTF8.GetString(codeDecodedBytes);

var result = await _userManager.ConfirmEmailAsync(user, decodedCode);
if (result.Succeeded)
{
return user.Id;
}
else
{
return 0;
}
}


}
}
3 changes: 3 additions & 0 deletions src/LetsDisc.Web.Host/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ testem.log
#System Files
.DS_Store
Thumbs.db

#Config Files
firebase.config.ts
13 changes: 12 additions & 1 deletion src/LetsDisc.Web.Host/LetsDisc.Web.Host.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>LetsDisc.Web.Host</AssemblyName>
Expand Down Expand Up @@ -81,19 +82,26 @@
<None Remove="src\app\tenants\**" />
</ItemGroup>
<ItemGroup>
<None Remove="src\app\account\login.service.ts" />
<None Remove="src\app\comma-separted.pipe.spec.ts" />
<None Remove="src\app\comma-separted.pipe.ts" />
<None Remove="src\app\comma-seperated.pipe.ts" />
<None Remove="src\app\pipes\remove-html-tag.pipe.ts" />
<None Remove="src\app\pipes\truncate-text.pipe.ts" />
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Include="src\app\account\login.service.ts" />
<TypeScriptCompile Include="src\app\pipes\remove-html-tag.pipe.ts" />
<TypeScriptCompile Include="src\app\pipes\truncate-text.pipe.ts" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="ComputeFilesToPublish">
<Exec Command="ng build --prod" />
<Exec Command="robocopy $(MSBuildProjectDirectory)\wwwroot\dist\ $(MSBuildProjectDirectory)\wwwroot\ /S /E /MOVE" IgnoreExitCode="True" />
<Exec Command="robocopy &quot;$(MSBuildProjectDirectory)\wwwroot\dist\ &quot; &quot;$(MSBuildProjectDirectory)\wwwroot\ &quot; /S /E /MOVE" IgnoreExitCode="True" />
<ItemGroup>
<DistFiles Include="wwwroot\**\*" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
Expand All @@ -105,4 +113,7 @@
<PropertyGroup>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:\Gensler Work\Personal Work\LetsDisc\src\LetsDisc.Web.Host\LetsDisc.Web.Host.xml</DocumentationFile>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions src/LetsDisc.Web.Host/LetsDisc.Web.Host.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/LetsDisc.Web.Host/Startup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSetting("detailedErrors", "true")
.CaptureStartupErrors(true)
.Build();
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/LetsDisc.Web.Host/Startup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using Microsoft.AspNetCore.Http;
using System.Security.Principal;
using Microsoft.Extensions.FileProviders;
using LetsDisc.EntityFrameworkCore;
using Microsoft.AspNetCore.StaticFiles;

namespace LetsDisc.Web.Host.Startup
{
Expand All @@ -28,10 +30,12 @@ public class Startup
private const string _defaultCorsPolicyName = "localhost";

private readonly IConfigurationRoot _appConfiguration;
private readonly IHostingEnvironment _hostingEnvironment;

public Startup(IHostingEnvironment env)
{
_appConfiguration = env.GetAppConfiguration();
_hostingEnvironment = env;
}

public IServiceProvider ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -101,7 +105,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
return services.AddAbp<LetsDiscWebHostModule>(
// Configure Log4Net logging
options => options.IocManager.IocContainer.AddFacility<LoggingFacility>(
f => f.UseAbpLog4Net().WithConfig("log4net.config")
f => f.UseAbpLog4Net().WithConfig(Path.Combine(_hostingEnvironment.ContentRootPath, "log4net.config"))
)
);
}
Expand All @@ -113,17 +117,20 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseCors(_defaultCorsPolicyName); // Enable CORS!

app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index.html"; await next(); } });


app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()

//app.UseStaticFiles();
/*app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
FileProvider = new PhysicalFileProvider(Path.Combine(_hostingEnvironment.ContentRootPath, "Resources")),
RequestPath = new PathString("/Resources")
});
});*/

app.UseAuthentication();
app.UseAbpRequestLocalization();


app.UseSignalR(routes =>
{
routes.MapHub<AbpCommonHub>("/signalr");
Expand Down
8 changes: 6 additions & 2 deletions src/LetsDisc.Web.Host/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"src/bsb-theme/css/materialize.css",
"src/bsb-theme/css/style.css",
"src/bsb-theme/css/themes/all-themes.css",
"src/shared/core.less"
"src/shared/core.less",
"node_modules/firebaseui/dist/firebaseui.css",
"node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
Expand Down Expand Up @@ -184,7 +186,9 @@
"src/bsb-theme/css/materialize.css",
"src/bsb-theme/css/style.css",
"src/bsb-theme/css/themes/all-themes.css",
"src/shared/core.less"
"src/shared/core.less",
"node_modules/firebaseui/dist/firebaseui.css",
"node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
],
"assets": [
"src/assets",
Expand Down
9 changes: 0 additions & 9 deletions src/LetsDisc.Web.Host/appsettings.Staging.json

This file was deleted.

Loading