Invite Uninitialized
This commit is contained in:
@@ -60,7 +60,10 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
protected string ResetPassword(User user)
|
||||
{
|
||||
var passwordResetToken = Algorithms.GenerateToken();
|
||||
// don't make a new one if they already have an active token
|
||||
var passwordResetToken =
|
||||
user.PasswordResetToken ?? Algorithms.GenerateToken();
|
||||
|
||||
var url = LinkForUrlAction(
|
||||
Url.Action("NewPassword", "Account",
|
||||
new NewPasswordViewModel
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using MileageTraker.Web.Attributes;
|
||||
@@ -147,6 +149,29 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public JsonResult SendInvite(Guid userId)
|
||||
{
|
||||
var user = DataService.GetUser(userId);
|
||||
var resetPasswordUrl = ResetPassword(user);
|
||||
var email = new EmailNotificationService();
|
||||
email.SendInitializePassword(user, resetPasswordUrl);
|
||||
return Json(true, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Developer")]
|
||||
public ActionResult InviteUninitialized()
|
||||
{
|
||||
var uninitializedUsers =
|
||||
(from user in DataService.GetUsers()
|
||||
where user.LastPasswordChangedDate == SqlDateTime.MinValue.Value
|
||||
&& user.LastActivityDate == SqlDateTime.MinValue.Value
|
||||
&& user.IsApproved
|
||||
orderby user.Username
|
||||
select user).ToList();
|
||||
|
||||
return View(uninitializedUsers);
|
||||
}
|
||||
|
||||
public ActionResult Edit(Guid id)
|
||||
{
|
||||
var user = DataService.GetUser(id);
|
||||
|
||||
@@ -224,4 +224,5 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
/* End Form Validation */
|
||||
/* End Form Validation */
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
<div class="btn-toolbar pull-left">
|
||||
@Html.ActionLink("Add new User", "Create", null, new{@class="btn"})
|
||||
@Html.ActionLink("Export", "Export", null, new{@class="btn"})
|
||||
@if (User.IsInRole("Developer"))
|
||||
{
|
||||
@Html.ActionLink("Invite Uninintialized", "InviteUninitialized", null, new{@class="btn"})
|
||||
}
|
||||
</div>
|
||||
|
||||
<div id="users-online">Users online now: <span class="badge badge-info">@Membership.GetNumberOfUsersOnline()</span></div>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
@model List<MileageTraker.Web.Models.User>
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Invite Uninitialized Users";
|
||||
}
|
||||
|
||||
@{ Html.RenderPartial("BackToUsers"); }
|
||||
|
||||
@Html.Partial("_StatusMessage")
|
||||
|
||||
<h2 class="center-content">@ViewBag.Title</h2>
|
||||
|
||||
<div class="center-content well">
|
||||
<a href="#" id="invite-uninitialized-users" class="btn">Send Invitations</a>
|
||||
<h4>Inviting...</h4>
|
||||
<ul id="uninitialized-users">
|
||||
@foreach (var user in Model)
|
||||
{
|
||||
<li userId="@Html.Encode(user.UserId)">
|
||||
@Html.Encode(user.Username), @Html.Encode(user.Email)
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@section Scripts
|
||||
{
|
||||
<script type="text/javascript">
|
||||
// send invites
|
||||
$(function () {
|
||||
$("#invite-uninitialized-users").click(function () {
|
||||
sendInvites();
|
||||
$(this).addClass("disabled").off("click");
|
||||
return false;
|
||||
});
|
||||
|
||||
function sendInvites() {
|
||||
var $users = $("#uninitialized-users > li:not(.sent)");
|
||||
if ($users.length > 0) {
|
||||
var $li = $($users[0]);
|
||||
$.ajax({
|
||||
url: "/User/SendInvite",
|
||||
data: { userId: $li.attr("userId") },
|
||||
success: function () {
|
||||
$li.addClass("sent");
|
||||
$li.append('<span class="badge badge-success">Sent</span>');
|
||||
sendInvites();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -302,6 +302,7 @@
|
||||
<Content Include="Views\Account\NewPassword.cshtml" />
|
||||
<Content Include="Views\User\_LastActivity.cshtml" />
|
||||
<Content Include="Views\Shared\EditorTemplates\CheckBoxViewModel.cshtml" />
|
||||
<Content Include="Views\User\InviteUninitialized.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config">
|
||||
|
||||
Reference in New Issue
Block a user