Add profile pages to update your username and password.
This commit is contained in:
parent
7cc5de61fb
commit
444c547b15
9 changed files with 144 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import { AddNewTorrentComponent } from './add-new-torrent/add-new-torrent.compon
|
||||||
import { AuthResolverService } from './auth-resolver.service';
|
import { AuthResolverService } from './auth-resolver.service';
|
||||||
import { LoginComponent } from './login/login.component';
|
import { LoginComponent } from './login/login.component';
|
||||||
import { MainLayoutComponent } from './main-layout/main-layout.component';
|
import { MainLayoutComponent } from './main-layout/main-layout.component';
|
||||||
|
import { ProfileComponent } from './profile/profile.component';
|
||||||
import { SettingsComponent } from './settings/settings.component';
|
import { SettingsComponent } from './settings/settings.component';
|
||||||
import { SetupComponent } from './setup/setup.component';
|
import { SetupComponent } from './setup/setup.component';
|
||||||
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
||||||
|
|
@ -41,6 +42,10 @@ const routes: Routes = [
|
||||||
path: 'settings',
|
path: 'settings',
|
||||||
component: SettingsComponent,
|
component: SettingsComponent,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'profile',
|
||||||
|
component: ProfileComponent,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import { TorrentStatusPipe } from './torrent-status.pipe';
|
||||||
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
||||||
import { TorrentComponent } from './torrent/torrent.component';
|
import { TorrentComponent } from './torrent/torrent.component';
|
||||||
import { DecodeURIPipe } from './decode-uri.pipe';
|
import { DecodeURIPipe } from './decode-uri.pipe';
|
||||||
|
import { ProfileComponent } from './profile/profile.component';
|
||||||
|
|
||||||
curray();
|
curray();
|
||||||
|
|
||||||
|
|
@ -37,6 +38,7 @@ curray();
|
||||||
SetupComponent,
|
SetupComponent,
|
||||||
TorrentComponent,
|
TorrentComponent,
|
||||||
DecodeURIPipe,
|
DecodeURIPipe,
|
||||||
|
ProfileComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,11 @@ export class AuthService {
|
||||||
public logout() {
|
public logout() {
|
||||||
return this.http.post<void>(`/Api/Authentication/Logout`, {});
|
return this.http.post<void>(`/Api/Authentication/Logout`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public update(userName: string, password: string): Observable<void> {
|
||||||
|
return this.http.post<void>(`/Api/Authentication/Update`, {
|
||||||
|
userName,
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
<span class="navbar-link"> Account </span>
|
<span class="navbar-link"> Account </span>
|
||||||
|
|
||||||
<div class="navbar-dropdown is-right">
|
<div class="navbar-dropdown is-right">
|
||||||
<a class="navbar-item"> Profile </a>
|
<a class="navbar-item" routerLink="profile"> Profile </a>
|
||||||
<a class="navbar-item" (click)="logout()"> Logout </a>
|
<a class="navbar-item" (click)="logout()"> Logout </a>
|
||||||
<hr class="navbar-divider" />
|
<hr class="navbar-divider" />
|
||||||
<div class="navbar-item">Version 2.0.5</div>
|
<div class="navbar-item">Version 2.0.5</div>
|
||||||
|
|
@ -61,7 +61,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="notification is-warning" *ngIf="profile && profile.latestVersion && profile.currentVersion !== profile.latestVersion">
|
<div
|
||||||
|
class="notification is-warning"
|
||||||
|
*ngIf="profile && profile.latestVersion && profile.currentVersion !== profile.latestVersion"
|
||||||
|
>
|
||||||
Version {{ profile.latestVersion }} of RealDebrid Client was found. You are currently on version
|
Version {{ profile.latestVersion }} of RealDebrid Client was found. You are currently on version
|
||||||
{{ profile.currentVersion }}.
|
{{ profile.currentVersion }}.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
38
client/src/app/profile/profile.component.html
Normal file
38
client/src/app/profile/profile.component.html
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Login username</label>
|
||||||
|
<div class="control">
|
||||||
|
<input class="input" type="text" minlength="1" maxlength="100" [(ngModel)]="username" />
|
||||||
|
</div>
|
||||||
|
<p class="help">
|
||||||
|
This is the username you use to login Real-Debrid Client. Only change this if you want to change the username.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Login password</label>
|
||||||
|
<div class="control">
|
||||||
|
<input class="input" type="password" minlength="1" maxlength="100" [(ngModel)]="password" />
|
||||||
|
</div>
|
||||||
|
<p class="help">
|
||||||
|
This is the password you use to login Real-Debrid Client. Only change this if you want to change the password.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<div class="notification is-danger is-light" *ngIf="error != null">Error saving: {{ error }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<div class="notification is-success is-light" *ngIf="success">Your profile has been updated</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<button class="button is-success" (click)="save()" [disabled]="saving" [ngClass]="{ 'is-loading': saving }">
|
||||||
|
Save Profile
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
0
client/src/app/profile/profile.component.scss
Normal file
0
client/src/app/profile/profile.component.scss
Normal file
40
client/src/app/profile/profile.component.ts
Normal file
40
client/src/app/profile/profile.component.ts
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,5 +48,32 @@ namespace RdtClient.Service.Services
|
||||||
{
|
{
|
||||||
await _signInManager.SignOutAsync();
|
await _signInManager.SignOutAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IdentityResult> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,20 @@ namespace RdtClient.Web.Controllers
|
||||||
await _authentication.Logout();
|
await _authentication.Logout();
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("Update")]
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult> 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
|
public class AuthControllerLoginRequest
|
||||||
|
|
@ -97,4 +111,10 @@ namespace RdtClient.Web.Controllers
|
||||||
public String UserName { get; set; }
|
public String UserName { get; set; }
|
||||||
public String Password { get; set; }
|
public String Password { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AuthControllerUpdateRequest
|
||||||
|
{
|
||||||
|
public String UserName { get; set; }
|
||||||
|
public String Password { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue