Skip to content

Commit

Permalink
Fix organization invites.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Mar 8, 2020
1 parent bf5ae5d commit 49a4c85
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
19 changes: 3 additions & 16 deletions Server/API/OrganizationManagementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,10 @@ public async Task<IActionResult> SendInvite([FromBody]Invite invite)

if (!DataService.DoesUserExist(invite.InvitedUser))
{
var user = new RemotelyUser
{
UserName = invite.InvitedUser,
Email = invite.InvitedUser,
OrganizationID = orgID,
IsAdministrator = invite.IsAdmin
};
var result = await UserManager.CreateAsync(user);
if (result.Succeeded)
var result = await DataService.CreateUser(invite.InvitedUser, invite.IsAdmin, orgID);
if (result)
{
//if (!DataService.SetNewUserProperties(user.UserName, orgID, invite.IsAdmin))
//{
// return BadRequest();
//}


user = await UserManager.FindByEmailAsync(invite.InvitedUser);
var user = await UserManager.FindByEmailAsync(invite.InvitedUser);

await UserManager.ConfirmEmailAsync(user, await UserManager.GenerateEmailConfirmationTokenAsync(user));

Expand Down
14 changes: 3 additions & 11 deletions Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,10 @@ public async Task<IActionResult> SendInvite(RemotelyUser currentUser)
{
if (!DataService.DoesUserExist(Input.UserEmail))
{
var user = new RemotelyUser
{
UserName = Input.UserEmail,
Email = Input.UserEmail,
OrganizationID = currentUser.OrganizationID,
Organization = currentUser.Organization,
IsAdministrator = Input.IsAdmin
};
var result = await UserManager.CreateAsync(user);
if (result.Succeeded)
var result = await DataService.CreateUser(Input.UserEmail, Input.IsAdmin, currentUser.OrganizationID);
if (result)
{
user = await UserManager.FindByEmailAsync(Input.UserEmail);
var user = DataService.GetUserByName(Input.UserEmail);

await UserManager.ConfirmEmailAsync(user, await UserManager.GenerateEmailConfirmationTokenAsync(user));

Expand Down
28 changes: 28 additions & 0 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,34 @@ public async Task<ApiToken> CreateApiToken(string userName, string tokenName, st
return newToken;
}


public async Task<bool> CreateUser(string userEmail, bool isAdmin, string organizationID)
{
try
{
var user = new RemotelyUser()
{
UserName = userEmail.Trim().ToLower(),
Email = userEmail.Trim().ToLower(),
IsAdministrator = isAdmin,
OrganizationID = organizationID
};
var org = RemotelyContext.Organizations
.Include(x=>x.RemotelyUsers)
.FirstOrDefault(x=>x.ID == organizationID);
org.RemotelyUsers.Add(user);
await RemotelyContext.SaveChangesAsync();
return true;
}
catch (Exception ex)
{
WriteEvent(ex);
return false;
}

}


public async Task DeleteApiToken(string userName, string tokenId)
{
var user = RemotelyContext.Users.FirstOrDefault(x => x.UserName == userName);
Expand Down

0 comments on commit 49a4c85

Please sign in to comment.