diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 022f7bc..9b97f11 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import { AddNewTorrentComponent } from './add-new-torrent/add-new-torrent.compon import { AuthResolverService } from './auth-resolver.service'; import { LoginComponent } from './login/login.component'; import { MainLayoutComponent } from './main-layout/main-layout.component'; +import { ProfileComponent } from './profile/profile.component'; import { SettingsComponent } from './settings/settings.component'; import { SetupComponent } from './setup/setup.component'; import { TorrentTableComponent } from './torrent-table/torrent-table.component'; @@ -41,6 +42,10 @@ const routes: Routes = [ path: 'settings', component: SettingsComponent, }, + { + path: 'profile', + component: ProfileComponent, + }, ], }, ]; diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 4a464cd..633d6d0 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -20,6 +20,7 @@ import { TorrentStatusPipe } from './torrent-status.pipe'; import { TorrentTableComponent } from './torrent-table/torrent-table.component'; import { TorrentComponent } from './torrent/torrent.component'; import { DecodeURIPipe } from './decode-uri.pipe'; +import { ProfileComponent } from './profile/profile.component'; curray(); @@ -37,6 +38,7 @@ curray(); SetupComponent, TorrentComponent, DecodeURIPipe, + ProfileComponent, ], imports: [ BrowserModule, diff --git a/client/src/app/auth.service.ts b/client/src/app/auth.service.ts index 7378193..4e55561 100644 --- a/client/src/app/auth.service.ts +++ b/client/src/app/auth.service.ts @@ -29,4 +29,11 @@ export class AuthService { public logout() { return this.http.post(`/Api/Authentication/Logout`, {}); } + + public update(userName: string, password: string): Observable { + return this.http.post(`/Api/Authentication/Update`, { + userName, + password, + }); + } } diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index fc65fa8..38a1e1d 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -52,7 +52,7 @@ Account -
+
Version {{ profile.latestVersion }} of RealDebrid Client was found. You are currently on version {{ profile.currentVersion }}.
diff --git a/client/src/app/profile/profile.component.html b/client/src/app/profile/profile.component.html new file mode 100644 index 0000000..7b36833 --- /dev/null +++ b/client/src/app/profile/profile.component.html @@ -0,0 +1,38 @@ +
+ +
+ +
+

+ This is the username you use to login Real-Debrid Client. Only change this if you want to change the username. +

+
+
+ +
+ +
+

+ This is the password you use to login Real-Debrid Client. Only change this if you want to change the password. +

+
+ +
+
+
Error saving: {{ error }}
+
+
+ +
+
+
Your profile has been updated
+
+
+ +
+
+ +
+
diff --git a/client/src/app/profile/profile.component.scss b/client/src/app/profile/profile.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/profile/profile.component.ts b/client/src/app/profile/profile.component.ts new file mode 100644 index 0000000..6fb74e3 --- /dev/null +++ b/client/src/app/profile/profile.component.ts @@ -0,0 +1,40 @@ +import { Component, OnInit } from '@angular/core'; +import { AuthService } from '../auth.service'; + +@Component({ + selector: 'app-profile', + templateUrl: './profile.component.html', + styleUrls: ['./profile.component.scss'], +}) +export class ProfileComponent implements OnInit { + constructor(private authService: AuthService) {} + + public username: string; + public password: string; + + public saving = false; + public success: boolean; + public error: string; + + ngOnInit(): void { + + } + + public save(): void { + this.success = false; + this.error = null; + this.saving = true; + + this.authService.update(this.username, this.password).subscribe( + () => { + this.success = true; + this.saving = false; + }, + (err) => { + this.error = err.error; + this.success = false; + this.saving = false; + } + ); + } +} diff --git a/server/RdtClient.Service/Services/Authentication.cs b/server/RdtClient.Service/Services/Authentication.cs index a8a0a22..06e8ab5 100644 --- a/server/RdtClient.Service/Services/Authentication.cs +++ b/server/RdtClient.Service/Services/Authentication.cs @@ -48,5 +48,32 @@ namespace RdtClient.Service.Services { await _signInManager.SignOutAsync(); } + + public async Task Update(String newUserName, String newPassword) + { + var user = await GetUser(); + + if (user == null) + { + throw new Exception("No logged in user found"); + } + + if (!String.IsNullOrWhiteSpace(newUserName)) + { + user.UserName = newUserName; + } + + await _userManager.UpdateAsync(user); + + if (!String.IsNullOrWhiteSpace(newPassword)) + { + var token = await _userManager.GeneratePasswordResetTokenAsync(user); + var result = await _userManager.ResetPasswordAsync(user, token, newPassword); + + return result; + } + + return IdentityResult.Success; + } } } diff --git a/server/RdtClient.Web/Controllers/AuthController.cs b/server/RdtClient.Web/Controllers/AuthController.cs index 279a406..1d358f4 100644 --- a/server/RdtClient.Web/Controllers/AuthController.cs +++ b/server/RdtClient.Web/Controllers/AuthController.cs @@ -90,6 +90,20 @@ namespace RdtClient.Web.Controllers await _authentication.Logout(); return Ok(); } + + [Route("Update")] + [HttpPost] + public async Task Update([FromBody] AuthControllerUpdateRequest request) + { + var updateResult = await _authentication.Update(request.UserName, request.Password); + + if (!updateResult.Succeeded) + { + return BadRequest(updateResult.Errors.First().Description); + } + + return Ok(); + } } public class AuthControllerLoginRequest @@ -97,4 +111,10 @@ namespace RdtClient.Web.Controllers public String UserName { get; set; } public String Password { get; set; } } + + public class AuthControllerUpdateRequest + { + public String UserName { get; set; } + public String Password { get; set; } + } }