Skip to content

Commit

Permalink
Add deployment url to appsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasanker committed Feb 29, 2020
1 parent 0f66839 commit 3c42a24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions coffeecard/CoffeeCard/Configuration/EnvironmentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class EnvironmentSettings : IValidatable
public EnvironmentType EnvironmentType { get; set; }
[Required]
public string MinAppVersion { get; set; }
[Required]
public string DeploymentUrl { get; set; }

public void Validate()
{
Expand Down
5 changes: 5 additions & 0 deletions coffeecard/CoffeeCard/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ public string Login(string username, string password, string version)
public User RegisterAccount(RegisterDTO registerDto)
{
Log.Information($"Trying to register new user. Name: {registerDto.Name} Email: {registerDto.Email}");

if (_context.Users.Any(x => x.Email == registerDto.Email))
{
Log.Information($"Could not register user Name: {registerDto.Name}. Email:{registerDto.Email} already exists");
throw new ApiException($"The email {registerDto.Email} is already being used by another user", 400);
}

var salt = _hashService.GenerateSalt();
var hashedPassword = _hashService.Hash(registerDto.Password + salt);

Expand Down
8 changes: 4 additions & 4 deletions coffeecard/CoffeeCard/Services/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using MimeKit;
using RestSharp;
using RestSharp.Authenticators;
Expand All @@ -21,11 +19,13 @@ public class EmailService : IEmailService
private readonly MailgunSettings _mailgunSettings;
private readonly IHostingEnvironment _env;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly EnvironmentSettings _environmentSettings;

public EmailService(MailgunSettings mailgunSettings, IHostingEnvironment env,
public EmailService(MailgunSettings mailgunSettings, EnvironmentSettings environmentSettings, IHostingEnvironment env,
IHttpContextAccessor httpContextAccessor)
{
_mailgunSettings = mailgunSettings;
_environmentSettings = environmentSettings;
_env = env;
_httpContextAccessor = httpContextAccessor;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public void SendVerificationEmailForRecover(User user, int newPassword)
private (BodyBuilder, string) RetrieveTemplate(string templateName)
{
var fullPath = _httpContextAccessor.HttpContext?.Request?.GetDisplayUrl();
var baseUrl = "https://beta.analogio.dk/api/clippy/";
var baseUrl = _environmentSettings.DeploymentUrl;

var pathToTemplate = _env.WebRootPath
+ Path.DirectorySeparatorChar
Expand Down
3 changes: 2 additions & 1 deletion coffeecard/CoffeeCard/appsettings-for-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"AllowedHosts": "*",
"EnvironmentSettings": {
"EnvironmentType": "Test",
"MinAppVersion": "2"
"MinAppVersion": "2",
"DeploymentUrl": "None"
},
"DatabaseSettings": {
"ConnectionString": "None",
Expand Down

0 comments on commit 3c42a24

Please sign in to comment.