Add Email Service
This commit is contained in:
parent
d496c6bc70
commit
5833d3d08d
|
|
@ -10,7 +10,7 @@ export class Request
|
|||
|
||||
console.log( "post", url, ">>", input);
|
||||
xhr.open( "POST", url, true );
|
||||
|
||||
xhr.setRequestHeader( "Content-Type", "application/json");
|
||||
xhr.responseType = "text";
|
||||
|
||||
xhr.onload=
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ export abstract class RequestHandler
|
|||
getUser():Promise<UserData>
|
||||
{
|
||||
let request = this._currentRequest;
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
let tokenData = requestBody as { token:string };
|
||||
let tokenID = tokenData.token;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export class UserManagementServerSettings
|
|||
isDebugMode:boolean = false;
|
||||
httpsKeyPath:string;
|
||||
httpsCertPath:string;
|
||||
emailKey:string;
|
||||
|
||||
// Paths
|
||||
rootPath:string;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
import { Message } from "../../../browser/messages/Message";
|
||||
import { RJLog } from "../../log/RJLog";
|
||||
import { Request } from "../../web/Request";
|
||||
import { EmailService } from "./EmailService";
|
||||
|
||||
export class EmailData
|
||||
{
|
||||
to:string;
|
||||
subject:string;
|
||||
message:string;
|
||||
reply:string;
|
||||
key:string;
|
||||
}
|
||||
|
||||
export class RokojoriEmail extends EmailService
|
||||
{
|
||||
_key:string;
|
||||
|
||||
constructor( key:string )
|
||||
{
|
||||
super();
|
||||
this._key = key;
|
||||
}
|
||||
|
||||
async send( reply:string, to:string, subject:string, message:string ):Promise<void>
|
||||
{
|
||||
let emailData =
|
||||
{
|
||||
to: to,
|
||||
subject: subject,
|
||||
message: message,
|
||||
reply: reply,
|
||||
key: this._key
|
||||
};
|
||||
|
||||
let url = "https://rokojori.com/_php/backend/email.php";
|
||||
|
||||
let result = await Request.postJSON<EmailData,Message>( url, emailData );
|
||||
|
||||
RJLog.log( "Email", to, subject, ">>", result );
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ export class InfoHandler extends RequestHandler
|
|||
|
||||
async _handle( request:FastifyRequest, reply:FastifyReply )
|
||||
{
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
let tokenData = requestBody as { token:string };
|
||||
let tokenID = tokenData.token;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export class LoginHandler extends RequestHandler
|
|||
|
||||
async _handle( request:FastifyRequest, reply:FastifyReply )
|
||||
{
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
let { email, password, userName } = requestBody as { email: string; password: string; userName: string };
|
||||
|
||||
if ( ! email || ! password )
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export class LogoutHandler extends RequestHandler
|
|||
|
||||
async _handle( request:FastifyRequest, reply:FastifyReply )
|
||||
{
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
let tokenData = requestBody as { token:string };
|
||||
let tokenID = tokenData.token;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ export class SignUpHandler extends RequestHandler
|
|||
|
||||
async _handle( request:FastifyRequest, reply:FastifyReply )
|
||||
{
|
||||
RJLog.log( "Body:", request.body );
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
|
||||
let { email, password, userName } = requestBody as { email: string; password: string; userName: string };
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export class UserIsLoggedIn extends RequestRequirement
|
|||
|
||||
async handle( request:FastifyRequest, reply:FastifyReply ):Promise<boolean>
|
||||
{
|
||||
let requestBody = JSON.parse( request.body as string );
|
||||
let requestBody = request.body;
|
||||
let tokenData = requestBody as { token:string };
|
||||
|
||||
if ( ! tokenData )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
export class Request
|
||||
{
|
||||
|
||||
static async getJSON<O>(url: string): Promise<O>
|
||||
{
|
||||
let result = await fetch( url,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}
|
||||
);
|
||||
|
||||
if ( ! result.ok )
|
||||
{
|
||||
throw new Error( `GET ${url} failed: ${result.status} ${result.statusText}` );
|
||||
}
|
||||
|
||||
return result.json() as Promise<O>;
|
||||
}
|
||||
|
||||
static async postJSON<I, O>(url: string, input: I): Promise<O>
|
||||
{
|
||||
let result = await fetch(
|
||||
url,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify( input )
|
||||
});
|
||||
|
||||
if ( ! result.ok )
|
||||
{
|
||||
throw new Error( `POST ${url} failed: ${result.status} ${result.statusText}` );
|
||||
}
|
||||
|
||||
return result.json() as Promise<O>;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue