Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/delete user integration #469

Merged
merged 21 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9d05f73
Add delete user identity server endpoint and delete profile and forms…
irinel-nistor May 27, 2020
c93d342
Add adminApi policy to the delete endpoint
irinel-nistor May 28, 2020
c33d942
Merge branch 'develop' into DeleteUserEndpoint
irinel-nistor May 28, 2020
3f4238a
Delete only the IDP user
irinel-nistor Jun 3, 2020
9173bb3
Revert user service changes
irinel-nistor Jun 3, 2020
99c5588
revert config
irinel-nistor Jun 3, 2020
ad218d9
Merge branch 'develop' into DeleteUserEndpoint
RaduCStefanescu Jun 27, 2020
26d8ca0
Adding delete account
mmircea16 Jun 27, 2020
d0271c7
Using the identity server URL
mmircea16 Jun 27, 2020
a2b5fcb
Fixing browser warning
mmircea16 Jun 27, 2020
7b49d6a
Merge branch 'develop' into DeleteUserEndpoint
RaduCStefanescu Jun 27, 2020
62e0661
Update frontend/src/components/DeleteAccount/index.js
mmircea16 Jun 28, 2020
9acf30c
Merge branch 'develop' into delete-account
RaduCStefanescu Jun 29, 2020
542605c
Merge branch 'develop' into DeleteUserEndpoint
RaduCStefanescu Jun 29, 2020
1189d75
Merge remote-tracking branch 'origin/delete-account' into feature/del…
Jul 7, 2020
f2dce7c
Merge branch 'pr/442' into feature/delete-user-integration
Jul 7, 2020
b9095c0
Integrate delete user backend + frontend
Jul 8, 2020
468a502
fix cors, moved remove functionality to account endpoint
Jul 8, 2020
80b2938
Update frontend/src/components/DeleteAccount/index.js
idormenco Jul 22, 2020
8988f64
Merge branch 'develop' into feature/delete-user-integration
idormenco Jul 31, 2020
576f318
linter fix
idormenco Jul 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using StamAcasa.IdentityServer.Quickstart.Account;

namespace IdentityServer.Quickstart.Account
{
Expand Down Expand Up @@ -212,6 +213,32 @@ public IActionResult AccessDenied()
return View();
}

[Route("account/delete")]
[HttpPost]
public async Task<IActionResult> DeleteAccountAsync([FromBody] DeleteAccountModel model)
{
var user = await _userManager.FindByNameAsync(model.Email);
if (user == null)
{
return Problem("Utilizatorul nu a fost sters");
}

if (!await _userManager.CheckPasswordAsync(user, model.Password))
{
return Problem("Utilizatorul nu a fost sters");
}

var result = await _userManager.DeleteAsync(user);
var userId = await _userManager.GetUserIdAsync(user);
if (!result.Succeeded)
{
throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
}

await _signInManager.SignOutAsync();

return Ok();
}

/*****************************************/
/* helper APIs for the AccountController */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

using System.ComponentModel.DataAnnotations;

namespace StamAcasa.IdentityServer.Quickstart.Account
{
public class DeleteAccountModel
{
[Required]
public string Email { get; set; }

[Required]
public string Password { get; set; }
}
}
14 changes: 14 additions & 0 deletions backend/src/StamAcasa.IdentityServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ public void ConfigureServices(IServiceCollection services)
));
services.AddSingleton<IQueueService, QueueService>();
services.AddSingleton<PasswordValidationMessages>();

services.AddCors(options =>
{
// this defines a CORS policy called "default"
options.AddPolicy("default", policy =>
{
policy = _identityConfiguration.Clients.SelectMany(x => x.AllowedCorsOrigins)
.Aggregate(policy, (current, url) => current.WithOrigins(url));

policy.AllowAnyHeader()
.AllowAnyMethod();
});
});
}

private X509Certificate2 LoadCertificate(string base64EncodedCertificate, string password)
Expand All @@ -140,6 +153,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHttpsRedirection();
}

app.UseCors("default");
app.UseRouting();
app.UseStaticFiles();
var cookiePolicyOptions = new CookiePolicyOptions
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/api/accountApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";
import { Constants } from "../config/constants";

const api = axios.create({
baseURL: `${Constants.idpUrl}/account/`
});

const AccountApi = {
deleteAccount: (email, password) => api.post("delete", { email, password })
RaduCStefanescu marked this conversation as resolved.
Show resolved Hide resolved
};

export default AccountApi;
2 changes: 2 additions & 0 deletions frontend/src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ export const getUserToken = async () => {
}
return user.access_token;
};

export const removeUser = () => userManager.removeUser();
69 changes: 69 additions & 0 deletions frontend/src/components/DeleteAccount/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useState } from "react";
import SidebarLayout from "../SidebarLayout";
import AccountApi from "../../api/accountApi";
import "./style.scss";
import { removeUser, getUser } from "../../api/auth";
const DeleteAccount = () => {
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [errorDeleting, setErrorDeleting] = useState(false);

const fieldsFilled = password;

const updatePassword = event => setPassword(event.target.value);

const deleteProfile = async () => {
try {
setLoading(true);
const user = await getUser();
await AccountApi.deleteAccount(user.profile.email, password);
setLoading(false);
await removeUser();
} catch {
setErrorDeleting(true);
setLoading(false);
}
};

const buttonClasses = "button is-danger" + (loading ? " is-loading" : "");
return (
<SidebarLayout>
<div>
Contul tău va fi șters. Pentru a putea reutiliza această aplicație va
trebui să îți refaci contul de utilizator. Informațiile pe care le-ai
transmis până acum prin intermediul aplicație vor rămâne stocate în baza
idormenco marked this conversation as resolved.
Show resolved Hide resolved
de date. Dacă dorești ca toate informațiile să fie eliminate din baza de
date te rugăm să adresezi această cerere către:
<p>Adresa: Strada Italiană, nr. 22, Sector 2, 020976, București</p>
<p>E-mail: [email protected]</p>
</div>
<form onSubmit={() => {}}>
<div className="field">
<label className="label">Parola</label>
<input
className="input is-medium"
type="password"
placeholder="Parola"
value={password}
onChange={updatePassword}
/>
</div>
<div className="field">
<button
className={buttonClasses}
onClick={deleteProfile}
disabled={!fieldsFilled || loading}
>
Șterge cont
</button>
</div>
</form>
<div className="notification is-warning" hidden={!errorDeleting}>
<button className="delete" onClick={() => setErrorDeleting(false)} />
Încercarea de ștergere a eșuat!
</div>
</SidebarLayout>
);
};

export default DeleteAccount;
3 changes: 3 additions & 0 deletions frontend/src/components/DeleteAccount/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.notification {
margin-top: 1em;
}
1 change: 1 addition & 0 deletions frontend/src/components/Header/ProfileItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ProfileItems = () => {
<NavLink to="/account">Contul meu</NavLink>
<div className="account-separator" />
<button onClick={handleLogout}>Logout</button>
<NavLink to="/delete-account">Ștergere cont</NavLink>
</>
) : (
<>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UpdateProfile from "./components/UpdateProfile";
import Evaluation from "./components/Evaluation";
import Account from "./components/Account";
import TermsAndConditions from "./components/TermsAndConditions";
import DeleteAccount from "./components/DeleteAccount";

import {
redirectSilentSignin,
Expand Down Expand Up @@ -75,6 +76,10 @@ export const ROUTES = {
updateprofile: {
path: "/update-profile",
component: UpdateProfile
},
deleteaccount: {
path: "/delete-account",
component: DeleteAccount
}
}
};
2 changes: 2 additions & 0 deletions frontend/src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@import "~bulma/sass/utilities/_all.sass";
@import "~bulma/sass/base/_all.sass";
@import "~bulma/sass/elements/container.sass";
@import "~bulma/sass/elements/notification.sass";
@import "~bulma/sass/elements/other.sass";
@import "~bulma/sass/grid/columns.sass";

@import "~bulma/sass/components/tabs";