Skip to content

Commit

Permalink
Handle user profile updates from webpage
Browse files Browse the repository at this point in the history
  • Loading branch information
marvac committed Jan 17, 2019
1 parent f7ab618 commit df352c5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ActivatedRoute } from '@angular/router';
import { User } from 'src/app/models/user';
import { AlertifyService } from 'src/app/services/alertify.service';
import { NgForm } from '@angular/forms';
import { UserService } from 'src/app/services/user.service';
import { AuthService } from 'src/app/services/auth.service';

@Component({
selector: 'app-member-edit',
Expand All @@ -20,7 +22,12 @@ export class MemberEditComponent implements OnInit {

user: User;

constructor(private route: ActivatedRoute, private alertify: AlertifyService) { }
constructor(
private route: ActivatedRoute,
private alertify: AlertifyService,
private userService: UserService,
private authService: AuthService
) { }

ngOnInit() {
this.route.data.subscribe(data => {
Expand All @@ -29,7 +36,14 @@ export class MemberEditComponent implements OnInit {
}

updateUser() {
this.alertify.success("Changes were saved");
this.editForm.reset(this.user);
const userId = this.authService.decodedToken.nameid;
this.userService.updateUser(+userId, this.user)
.subscribe(next => {
this.alertify.success("Changes were saved");
this.editForm.reset(this.user);
}, error => {
this.alertify.error(error);
});

}
}
4 changes: 4 additions & 0 deletions Client/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export class UserService {
getUser(id): Observable<User> {
return this.http.get<User>(`${this.usersUrl}${id}`);
}

updateUser(id: number, user: User) {
return this.http.put(`${this.usersUrl}${id}`, user);
}
}
14 changes: 14 additions & 0 deletions Helpers/CloudSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Friendster.Helpers
{
public class CloudSettings
{
public string CloudName { get; set; }
public string ApiKey { get; set; }
public string ApiSecret { get; set; }
}
}
1 change: 1 addition & 0 deletions Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddTransient<Seeder>();

services.Configure<CloudSettings>(Configuration.GetSection("CloudSettings"));
services.AddScoped<IDataRepository, DataRepository>();
services.AddScoped<IAuthRepository, AuthRepository>();
services.AddScoped<IFriendRepository, FriendRepository>();
Expand Down
7 changes: 6 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"Default": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"CloudSettings": {
"CloudName": "dxtg2ci0b",
"ApiKey": "881683384793647",
"ApiSecret": "G_N5n6ZKQfJyzSMcXIfOf6wwNMA"
}
}

0 comments on commit df352c5

Please sign in to comment.