Browse Source

Added initial portion of Recovery Email option.

tags/2.0.3
Teknikode 4 years ago
parent
commit
1821cf75ad

+ 17
- 0
Teknik/Areas/User/Controllers/UserController.cs View File

@@ -19,6 +19,7 @@ using Teknik.ViewModels;
using System.Windows;
using System.Net;
using Teknik.Areas.Users.Utility;
using Teknik.Helpers;
using Teknik.Filters;

namespace Teknik.Areas.Users.Controllers
@@ -237,12 +238,28 @@ namespace Teknik.Areas.Users.Controllers
return Json(new { error = "Passwords must match" });
}

// PGP Key valid?
if (!string.IsNullOrEmpty(model.PublicKey) && !PGP.IsPublicKey(model.PublicKey))
{
return Json(new { error = "Invalid PGP Public Key" });
}

try
{
User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username;
if (!string.IsNullOrEmpty(model.RecoveryEmail))
{
string recoveryCode = Teknik.Utility.RandomString(24);
string resetUrl = Url.SubRouteUrl("user", "User.ResetPassword", new { Username = model.Username });
string verifyUrl = Url.SubRouteUrl("user", "User.VerifyRecoveryEmail", new { Username = model.Username, Code = recoveryCode });
//UserHelper.SendRecoveryEmailVerification(Config, model.Username, model.RecoveryEmail, resetUrl, verifyUrl); Not yet :)
//newUser.RecoveryEmail = model.RecoveryEmail;
}
newUser.UserSettings = new UserSettings();
if (!string.IsNullOrEmpty(model.PublicKey))
newUser.UserSettings.PGPSignature = model.PublicKey;
newUser.BlogSettings = new BlogSettings();
newUser.UploadSettings = new UploadSettings();


+ 11
- 2
Teknik/Areas/User/Models/User.cs View File

@@ -14,6 +14,12 @@ namespace Teknik.Areas.Users.Models

public string HashedPassword { get; set; }

public string RecoveryEmail { get; set; }

public string RecoveryVerifyCode { get; set; }

public bool RecoveryVerified { get; set; }

public bool TransferAccount { get; set; }

public DateTime JoinDate { get; set; }
@@ -34,8 +40,11 @@ namespace Teknik.Areas.Users.Models

public User()
{
Username = String.Empty;
HashedPassword = String.Empty;
Username = string.Empty;
HashedPassword = string.Empty;
RecoveryEmail = string.Empty;
RecoveryVerifyCode = string.Empty;
RecoveryVerified = false;
JoinDate = DateTime.Now;
LastSeen = DateTime.Now;
Groups = new List<Group>();

+ 16
- 0
Teknik/Areas/User/UserAreaRegistration.cs View File

@@ -50,6 +50,22 @@ namespace Teknik.Areas.Users
new { controller = "User", action = "Settings" }, // Parameter defaults
new[] { typeof(Controllers.UserController).Namespace }
);
context.MapSubdomainRoute(
"User.ResetPassword", // Route name
new List<string>() { "user" }, // Subdomains
new List<string>() { config.Host }, // domains
"Reset/{username}", // URL with parameters
new { controller = "User", action = "ResetPassword", username = UrlParameter.Optional }, // Parameter defaults
new[] { typeof(Controllers.UserController).Namespace }
);
context.MapSubdomainRoute(
"User.VerifyRecoveryEmail", // Route name
new List<string>() { "user" }, // Subdomains
new List<string>() { config.Host }, // domains
"VerifyEmail/{username}/{code}", // URL with parameters
new { controller = "User", action = "VerifyRecoveryEmail" }, // Parameter defaults
new[] { typeof(Controllers.UserController).Namespace }
);
context.MapSubdomainRoute(
"User.Index", // Route name
new List<string>() { "user" }, // Subdomains

+ 31
- 0
Teknik/Areas/User/Utility/UserHelper.cs View File

@@ -4,6 +4,7 @@ using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
@@ -321,6 +322,36 @@ namespace Teknik.Areas.Users.Utility
throw new Exception("Unable to delete user.", ex);
}
}

public static void SendRecoveryEmailVerification(Config config, string username, string email, string resetUrl, string verifyUrl)
{
SmtpClient client = new SmtpClient();
client.Host = config.ContactConfig.Host;
client.Port = config.ContactConfig.Port;
client.EnableSsl = config.ContactConfig.SSL;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential(config.NoReplyEmail, config.ContactConfig.Password);
client.Timeout = 5000;

MailMessage mail = new MailMessage(config.NoReplyEmail, email);
mail.Subject = "Recovery Email Validation";
mail.Body = string.Format(@"Thank you {0} for signing up for Teknik!

You are recieving this email because you have specified this email address as your recovery email. In the event that you forget your password, you can visit {1} and request a temporary password reset key be sent to this email. You will then be able to reset and choose a new password.

In order to verify that you own this email, please click the following link or paste it into your browser: {2}

If you recieved this email and you did not sign up for an account, please email us at {3} and ignore the verification link.

Thank you and enjoy!

- Teknik Administration", username, resetUrl, verifyUrl, config.SupportEmail);
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;

client.Send(mail);
}
#endregion

#region Email Management

+ 6
- 0
Teknik/Areas/User/ViewModels/RegisterViewModel.cs View File

@@ -23,6 +23,12 @@ namespace Teknik.Areas.Users.ViewModels
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }

[Display(Name = "Recovery Email")]
public string RecoveryEmail { get; set; }

[Display(Name = "Public PGP Key")]
public string PublicKey { get; set; }

public string ReturnUrl { get; set; }
}
}

+ 6
- 0
Teknik/Areas/User/Views/User/Register.cshtml View File

@@ -18,6 +18,12 @@
<div class="form-group">
<input type="password" class="form-control" id="registerConfirmPassword" value="" placeholder="Confirm Password" name="Register.ConfirmPassword" data-val-required="The Confirm Password field is required." data-val="true" />
</div>
<div class="form-group">
<input type="text" class="form-control" id="registerRecoveryEmail" value="" placeholder="Recovery Email (Optional)" name="Register.RecoveryEmail" />
</div>
<div class="form-group">
<textarea class="form-control" id="registerPublicKey" name="Register.PublicKey" placeholder="PGP Public Key (Optional)" title="enter your pgp public key" rows="5"></textarea>
</div>
<p class="text-center">
<small>
Username must meet the following requirements: <var>@Model.Config.UserConfig.UsernameFilterLabel</var><br />

+ 1
- 1
Teknik/Areas/User/Views/User/Settings.cshtml View File

@@ -48,7 +48,7 @@
</div>
<div class="col-sm-8">
<label for="update_pgp_public_key"><h4>Public Key</h4></label>
<textarea class="form-control" id="update_pgp_public_key" name="update_pgp_public_key" placeholder="Public Key Here" title="enter your blog's description" rows="10">@Model.UserSettings.PGPSignature</textarea>
<textarea class="form-control" id="update_pgp_public_key" name="update_pgp_public_key" placeholder="Public Key Here" title="enter your pgp public key" rows="10">@Model.UserSettings.PGPSignature</textarea>
</div>
</div>
<div class="row">

+ 3
- 0
Teknik/Configuration/Config.cs View File

@@ -19,6 +19,7 @@ namespace Teknik.Configuration
private string _Author;
private string _Host;
private string _SupportEmail;
private string _NoReplyEmail;
private string _BitcoinAddress;
private string _Salt1;
private string _Salt2;
@@ -46,6 +47,7 @@ namespace Teknik.Configuration
public string Author { get { return _Author; } set { _Author = value; } }
public string Host { get { return _Host; } set { _Host = value; } }
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
public string NoReplyEmail { get { return _NoReplyEmail; } set { _NoReplyEmail = value; } }
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
public string Salt1 { get { return _Salt1; } set { _Salt1 = value; } }
public string Salt2 { get { return _Salt2; } set { _Salt2 = value; } }
@@ -111,6 +113,7 @@ namespace Teknik.Configuration
Author = string.Empty;
Host = string.Empty;
SupportEmail = string.Empty;
NoReplyEmail = string.Empty;
BitcoinAddress = string.Empty;
Salt1 = string.Empty;
Salt2 = string.Empty;

Loading…
Cancel
Save