summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2015-04-26 11:14:59 -0700
committermatthewsotoudeh <matthewsot@outlook.com>2015-04-26 11:14:59 -0700
commit31304200c4c56b42e040a0a243ead5f274139dcf (patch)
treefb0a74397708c0f0b2e57478caed87c9cf17a6cc
parentb1c1398668561aae9fd86fe8436c68c52dfe5323 (diff)
cleaned up AccountAPIController a bit
-rw-r--r--LHSCamp/LHSCamp/Controllers/AccountAPIController.cs153
-rw-r--r--LHSCamp/LHSCamp/Views/Account/ResetPass.cshtml89
-rw-r--r--LHSCamp/LHSCamp/Views/Account/_ChangeEmailPartial.cshtml15
-rw-r--r--LHSCamp/LHSCamp/Views/Account/_ChangePasswordPartial.cshtml33
-rw-r--r--LHSCamp/LHSCamp/Views/Account/_RemoveAccountPartial.cshtml34
-rw-r--r--LHSCamp/LHSCamp/Views/Account/_SetPasswordPartial.cshtml32
-rw-r--r--LHSCamp/LHSCamp/Views/Candidates/GetCandidate.cshtml1
7 files changed, 31 insertions, 326 deletions
diff --git a/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs b/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs
index dc3d066..5fc2ad9 100644
--- a/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs
+++ b/LHSCamp/LHSCamp/Controllers/AccountAPIController.cs
@@ -26,72 +26,6 @@ namespace LHSCamp.Controllers
return Ok(exists ? "exists" : "new");
}
- [AllowAnonymous]
- [HttpPost]
- [Route("API/Account/StartResetPass")]
- public IHttpActionResult StartResetPassword(UserNameModel model)
- {
- using (var userManager = new UserManager<Candidate>(
- new Microsoft.AspNet.Identity.EntityFramework.UserStore<Candidate>(db)))
- {
- //Thanks! http://stackoverflow.com/questions/19539579/how-to-implement-a-tokenprovider-in-asp-net-identity-1-1-nightly-build
- if (Startup.DataProtectionProvider != null)
- {
- userManager.PasswordResetTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("PasswordReset"));
- userManager.UserConfirmationTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("ConfirmUser"));
- }
- var user = db.Users.FirstOrDefault(u => u.UserName == model.username);
-
- if (user == null || string.IsNullOrWhiteSpace(user.Email))
- {
- return Ok("problem");
- }
-
- //Thanks! http://csharp.net-informations.com/communications/csharp-smtp-mail.htm
- var settings = Config.GetValues(new[] { "SMTP Server", "SMTP Port", "SMTP User", "SMTP Pass" });
- var mail = new MailMessage();
- var smtpServer = new SmtpClient(settings["SMTP Server"]);
- mail.From = new MailAddress("postmaster@lhscampaign.cf", "LHS|Campaign");
- var userName = User.Identity.GetUserName();
- mail.To.Add(new MailAddress(user.Email, userName));
- mail.Subject = "Reset Your Password";
- mail.Body = "Please visit http://lhscampaign.cf/Account/ResetPass?token=";
- var token = userManager.GetPasswordResetToken(user.Id);
- mail.Body += HttpUtility.UrlEncode(token) + "&userId=" + user.Id;
- mail.Body += " to reset your LHS|Campaign password.";
-
- smtpServer.Port = int.Parse(settings["SMTP Port"]);
- smtpServer.Credentials = new System.Net.NetworkCredential(settings["SMTP User"], settings["SMTP Pass"]);
-
- smtpServer.Send(mail);
- return Ok("sent");
- }
- }
-
- [AllowAnonymous]
- [HttpPost]
- [Route("API/Account/ResetPass")]
- public IHttpActionResult ResetPassword(ResetPassModel model)
- {
- using (var userManager = new UserManager<Candidate>(
- new Microsoft.AspNet.Identity.EntityFramework.UserStore<Candidate>(db)))
- {
- // Thanks! http://stackoverflow.com/questions/19539579/how-to-implement-a-tokenprovider-in-asp-net-identity-1-1-nightly-build
- if (Startup.DataProtectionProvider != null)
- {
- userManager.PasswordResetTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("PasswordReset"));
- userManager.UserConfirmationTokens = new DataProtectorTokenProvider(Startup.DataProtectionProvider.Create("ConfirmUser"));
- }
-
- var result = userManager.ResetPassword(model.userId, model.token, model.password);
- if (result.Succeeded)
- {
- return Ok("set");
- }
- }
- return Ok("problem");
- }
-
[HttpPost]
[Route("API/Account/SetEmail")]
public IHttpActionResult SetEmail(SetEmailModel model)
@@ -113,20 +47,16 @@ namespace LHSCamp.Controllers
[Route("API/Account/SetPosition")]
public IHttpActionResult SetPosition(SetPositionModel model)
{
- var userId = User.Identity.GetUserId();
- var user = db.Users.Find(userId);
+ var user = db.Users.Find(User.Identity.GetUserId());
if (user == null)
{
return Ok("no user");
}
- if (!user.IsCandidate)
- {
- return Ok("set");
- }
- user.Candidate.Position = model.position;
+ user.Position = model.position;
db.SaveChanges();
+
return Ok("set");
}
@@ -134,21 +64,14 @@ namespace LHSCamp.Controllers
[Route("API/Account/SetReasons")]
public IHttpActionResult SetReasons(SetReasonsModel model)
{
- var userId = User.Identity.GetUserId();
+ var candidate = db.Users.Find(User.Identity.GetUserId());
- var user = db.Users.Find(userId);
- if (user == null)
- {
- return Ok("no user");
- }
-
- var candidate = user.Candidate;
if (candidate == null)
{
- return Ok("not candidate");
+ return Ok("no user");
}
- candidate.Reasons = model.reasons;
+ candidate.Platform = model.reasons;
db.SaveChanges();
return Ok("set");
}
@@ -159,33 +82,26 @@ namespace LHSCamp.Controllers
{
model.facebook = string.IsNullOrWhiteSpace(model.facebook) ? null : model.facebook.Trim();
- var user = db.Users.Find(User.Identity.GetUserId());
- if (user == null)
+ var candidate = db.Users.Find(User.Identity.GetUserId());
+ if (candidate == null)
{
return Ok("no user");
}
- var candidate = user.Candidate;
- if (candidate == null)
+ var existingFacebook = candidate.ExternalLinks.FirstOrDefault(link => link.Label == "VIEW FB EVENT");
+ if (existingFacebook != null)
{
- return Ok("no candidate");
+ candidate.ExternalLinks.Remove(existingFacebook);
}
- candidate.Facebook = model.facebook;
+ candidate.ExternalLinks.Add(new ExternalLink()
+ {
+ Label = "VIEW FB EVENT",
+ Link = model.facebook
+ });
db.SaveChanges();
- return Ok("set");
- }
- [HttpPost]
- [Route("API/Account/SetPass")]
- public IHttpActionResult SetPass(SetPassModel model)
- {
- using (var userManager = new UserManager<Candidate>(
- new Microsoft.AspNet.Identity.EntityFramework.UserStore<Candidate>(db)))
- {
- var result = userManager.ChangePassword(User.Identity.GetUserId(), model.currPass, model.newPass);
- return Ok(result.Succeeded ? "set" : "nope");
- }
+ return Ok("set");
}
[HttpPost]
@@ -201,9 +117,9 @@ namespace LHSCamp.Controllers
// TODO: Should be validating with ModelState
if (model.Password.Length <= 6) errors.Add("Password");
if (!(model.Year <= 2018 && model.Year >= 2016)) errors.Add("Year");
- if (model.Position == null || model.Position.Length > 50) errors.Add("Position");
+ if (string.IsNullOrWhiteSpace(model.Position) || model.Position.Length > 50) errors.Add("Position");
model.Position = model.Position.ToLower();
- if (model.FullName == null || model.FullName.Length > 50) errors.Add("FullName");
+ if (string.IsNullOrWhiteSpace(model.FullName) || model.FullName.Length > 50) errors.Add("FullName");
if (db.Users.Count(usr => usr.UserName == model.Username) > 0) errors.Add("Username");
if (errors.Count > 0)
@@ -211,30 +127,23 @@ namespace LHSCamp.Controllers
return Ok(string.Join(",", errors) + ",");
}
- var user = new Candidate { UserName = model.Username, Email = model.Email, GraduationYear = model.Year };
+ var candidate = new Candidate
+ {
+ UserName = model.Username,
+ Email = model.Email,
+ GraduationYear = model.Year,
+ Position = model.Position,
+ Name = model.FullName
+ };
+
var preConf = db.PreConfs.FirstOrDefault(conf => conf.Email == model.Email.ToLower());
- if(preConf != null)
+ if (preConf != null)
{
- user.IsConfirmed = true;
+ candidate.IsConfirmed = true;
db.PreConfs.Remove(preConf);
}
- if (!string.IsNullOrWhiteSpace(model.Position))
- {
- if (string.IsNullOrWhiteSpace(model.FullName))
- {
- model.FullName = model.Username;
- }
-
- // create candidate for user
- user.Candidate = new Candidate
- {
- Owner = user,
- Position = model.Position,
- Name = model.FullName
- };
- }
- var result = await userManager.CreateAsync(user, model.Password);
+ var result = await userManager.CreateAsync(candidate, model.Password);
return Ok(result.Succeeded ? "GOOD" : string.Join(",", errors));
}
}
diff --git a/LHSCamp/LHSCamp/Views/Account/ResetPass.cshtml b/LHSCamp/LHSCamp/Views/Account/ResetPass.cshtml
deleted file mode 100644
index f5ef96c..0000000
--- a/LHSCamp/LHSCamp/Views/Account/ResetPass.cshtml
+++ /dev/null
@@ -1,89 +0,0 @@
-@{
- ViewBag.Title = "Reset Your Password";
- Layout = "~/Views/Shared/_HeroLayout.cshtml";
-}
-
-
-<div class="blue row medium-font" style="margin-top:100px;">
- <div class="logo-span large-font"><b>lhs</b>|campaign</div>
- <br />
- <div style="border-top:2px solid #fff;">
- <br />
- <div id="reset-form">
- <span class="large-font railway-bold">reset password</span>
- <br />
- <div id="reset-info">
- Please enter a new password for your account.
- </div>
- <div id="reset-error" style="display:none;">
- Sorry, something went wrong. Please try again.
- </div>
- <br /><br />
- <input type="password" id="pass" placeholder="password" class="default-input standard-input" />
- <br/>
- <input type="password" id="pass-conf" placeholder="confirm password" class="default-input standard-input" />
- <div class="medium-font railway-light" id="password-err" style="display:none;margin-top:10px;"></div>
- <script type="text/javascript">
- //Thanks! http://stackoverflow.com/questions/10438369/jquery-on-change-input-text
- $("#pass,#pass-conf").on('keyup', function () {
- if ($("#pass").val() != $("#pass-conf").val()) {
- $("#password-err").html("Your password doesn't match the confirmation");
- $("#password-err").show();
- }
- else if ($("#pass").val().length < 7) {
- $("#password-err").html("Please enter a password greater than 6 characters");
- $("#password-err").show();
- }
- else {
- $("#password-err").hide();
- }
- });
- </script>
- <br />
- <button id="reset-pass" class="default-btn default-btn">reset password</button>
- </div>
- <div id="reset-success" style="display:none;">
- <h1>Great, your password has been reset!</h1>
- You can now <a href="~/Account/Login" class="nunderline">login with your new password.</a>
- <br/><br/>
- Sending you there in 3...2...1...
- </div>
- <script type="text/javascript">
- $("#reset-pass").click(function () {
- var token = "@(ViewBag.Token)";
- var userId = "@(ViewBag.UserId)";
- var pass = $("#pass").val();
- var passConf = $("#pass-conf").val();
- if (pass != passConf) {
- $("#password-err").html("Your password doesn't match the confirmation");
- $("#password-err").show();
- }
- else if (pass.length < 7) {
- $("#password-err").html("Please enter a password greater than 6 characters");
- $("#password-err").show();
- }
- else {
- $.post("/API/Account/ResetPass", {
- "userId": userId,
- "token": token,
- "password": pass
- }, function (data) {
- if (data == "set") {
- $("#reset-form").fadeOut(function () {
- $("#reset-success").fadeIn();
- settimeout(function () {
- window.location.href = "/Account/Login";
- }, 1000);
- });
- }
- else {
- $("#reset-info").fadeOut(function () {
- $("#reset-error").fadeIn();
- });
- }
- });
- }
- });
- </script>
- </div>
-</div> \ No newline at end of file
diff --git a/LHSCamp/LHSCamp/Views/Account/_ChangeEmailPartial.cshtml b/LHSCamp/LHSCamp/Views/Account/_ChangeEmailPartial.cshtml
deleted file mode 100644
index e663e58..0000000
--- a/LHSCamp/LHSCamp/Views/Account/_ChangeEmailPartial.cshtml
+++ /dev/null
@@ -1,15 +0,0 @@
-@using Microsoft.AspNet.Identity
-@model LHSCamp.Models.ManageUserViewModel
-@using (Html.BeginForm("ModifyEmail", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
-{
- @Html.AntiForgeryToken()
- <h4>Change Email</h4>
- @Html.ValidationSummary("", new { @class = "text-danger" })
- @Html.TextBoxFor(m => m.Email, new { @class = "form-control default-input standard-input", placeholder = "email" })
-
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Change email" class="btn btn-default" />
- </div>
- </div>
-}
diff --git a/LHSCamp/LHSCamp/Views/Account/_ChangePasswordPartial.cshtml b/LHSCamp/LHSCamp/Views/Account/_ChangePasswordPartial.cshtml
deleted file mode 100644
index 1ada576..0000000
--- a/LHSCamp/LHSCamp/Views/Account/_ChangePasswordPartial.cshtml
+++ /dev/null
@@ -1,33 +0,0 @@
-@using Microsoft.AspNet.Identity
-@model LHSCamp.Models.ManageUserViewModel
-
-@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
-{
- @Html.AntiForgeryToken()
- <h4>Change Password</h4>
- @Html.ValidationSummary("", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(m => m.OldPassword, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.PasswordFor(m => m.OldPassword, new { @class = "form-control" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
- </div>
- </div>
-
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Change password" class="btn btn-default" />
- </div>
- </div>
-}
diff --git a/LHSCamp/LHSCamp/Views/Account/_RemoveAccountPartial.cshtml b/LHSCamp/LHSCamp/Views/Account/_RemoveAccountPartial.cshtml
deleted file mode 100644
index b4c8081..0000000
--- a/LHSCamp/LHSCamp/Views/Account/_RemoveAccountPartial.cshtml
+++ /dev/null
@@ -1,34 +0,0 @@
-@model ICollection<Microsoft.AspNet.Identity.UserLoginInfo>
-
-@if (Model.Count > 0)
-{
- <h4>Registered Logins</h4>
- <table class="table">
- <tbody>
- @foreach (var account in Model)
- {
- <tr>
- <td>@account.LoginProvider</td>
- <td>
- @if (ViewBag.ShowRemoveButton)
- {
- using (Html.BeginForm("Disassociate", "Account"))
- {
- @Html.AntiForgeryToken()
- <div>
- @Html.Hidden("loginProvider", account.LoginProvider)
- @Html.Hidden("providerKey", account.ProviderKey)
- <input type="submit" class="btn btn-default" value="Remove" title="Remove this @account.LoginProvider login from your account" />
- </div>
- }
- }
- else
- {
- @: &nbsp;
- }
- </td>
- </tr>
- }
- </tbody>
- </table>
-}
diff --git a/LHSCamp/LHSCamp/Views/Account/_SetPasswordPartial.cshtml b/LHSCamp/LHSCamp/Views/Account/_SetPasswordPartial.cshtml
deleted file mode 100644
index d6e6588..0000000
--- a/LHSCamp/LHSCamp/Views/Account/_SetPasswordPartial.cshtml
+++ /dev/null
@@ -1,32 +0,0 @@
-@model LHSCamp.Models.ManageUserViewModel
-
-<p class="text-info">
- You do not have a local username/password for this site. Add a local
- account so you can log in without an external login.
-</p>
-
-@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
-{
- @Html.AntiForgeryToken()
-
- <h4>Create Local Login</h4>
- <hr />
- @Html.ValidationSummary("", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Set password" class="btn btn-default" />
- </div>
- </div>
-}
diff --git a/LHSCamp/LHSCamp/Views/Candidates/GetCandidate.cshtml b/LHSCamp/LHSCamp/Views/Candidates/GetCandidate.cshtml
index a04c78b..adb7270 100644
--- a/LHSCamp/LHSCamp/Views/Candidates/GetCandidate.cshtml
+++ b/LHSCamp/LHSCamp/Views/Candidates/GetCandidate.cshtml
@@ -1,5 +1,4 @@
@using System.Text.RegularExpressions
-@using Microsoft.Ajax.Utilities
@model LHSCamp.Models.CandidateViewModel
@{
ViewBag.Description = (Model.Platform ?? "See " + Model.Name + "'s profile on LHSCampaign!");
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback