@@ -2,13 +2,16 @@ import decode from "jwt-decode";
22export default class AuthService {
33 // Initializing important variables
44
5+ user : Object ;
56 domain : string ;
67
78 constructor ( domain ?: string ) {
89 this . domain = domain || "http://localhost:8080" ; // API server domain
10+ this . user = Object ;
911 this . fetch = this . fetch . bind ( this ) ; // React binding stuff
1012 this . login = this . login . bind ( this ) ;
1113 this . getProfile = this . getProfile . bind ( this ) ;
14+ this . getUserInfos = this . getUserInfos . bind ( this ) ;
1215 }
1316
1417 login ( username : string , password : string ) {
@@ -64,6 +67,66 @@ export default class AuthService {
6467 return decode ( this . getToken ( ) ) ;
6568 }
6669
70+ getUserInfos ( ) {
71+ return this . fetch ( `${ this . domain } /user` , {
72+ method : "GET" ,
73+ } ) . then ( ( res ) => {
74+ return Promise . resolve ( res ) ;
75+ } ) ;
76+ }
77+
78+ editUser ( user : Object ) {
79+ return this . fetch ( `${ this . domain } /user` , {
80+ method : "PUT" ,
81+ body : JSON . stringify ( user )
82+ } ) . then ( ( res ) => {
83+ return Promise . resolve ( res ) ;
84+ } ) ;
85+ }
86+
87+ deleteUser ( ) {
88+ return this . fetch ( `${ this . domain } /user` , {
89+ method : "DELETE" ,
90+ } ) . then ( ( res ) => {
91+ return Promise . resolve ( res ) ;
92+ } ) ;
93+ }
94+
95+ createAccount ( user : Object ) {
96+ return this . fetch ( `${ this . domain } /user` , {
97+ method : "POST" ,
98+ body : JSON . stringify ( user )
99+ } ) . then ( ( res ) => {
100+ return Promise . resolve ( res ) ;
101+ } ) ;
102+ }
103+
104+ forgotPassword ( email : string ) {
105+ return this . fetch ( `${ this . domain } /user/forgottenpassword` , {
106+ method : "POST" ,
107+ body : email
108+ } ) . then ( ( res ) => {
109+ return Promise . resolve ( res ) ;
110+ } ) ;
111+ }
112+
113+ checkTokenPassword ( token : string ) {
114+ return this . fetch ( `${ this . domain } /reset/${ token } ` , {
115+ method : "GET"
116+ } ) . then ( ( res ) => {
117+ return Promise . resolve ( res ) ;
118+ } ) ;
119+ }
120+
121+ resetPassword ( token : string , password : string ) {
122+ return this . fetch ( `${ this . domain } /reset` , {
123+ method : "POST" ,
124+ body : JSON . stringify ( { "token" : token , "password" : password } )
125+ } ) . then ( ( res ) => {
126+ return Promise . resolve ( res ) ;
127+ } ) ;
128+ }
129+
67130 fetch ( url : any , options : any ) {
68131 // performs api calls sending the required authentication headers
69132 const headers = {
0 commit comments