monitor/src/app/utils/subscribe/invite.service.ts

27 lines
1012 B
TypeScript

import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import {COOKIE} from "../../openaireLibrary/login/utils/helper.class"
@Injectable()
export class InviteService {
constructor(private http:Http) {
}
inviteUsers(url:string, subject:string, body:string, recipients:string[]){
var email = {"subject":subject, "body":body, recipients: recipients };
return this.http.post(url+"/email", JSON.stringify(email), this.getAuthOptionsWithBody())
.map(res => <any> res.json())
.do(res => {console.log("Response is "+res)});
}
public getAuthOptionsWithBody():RequestOptions{
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('X-XSRF-TOKEN', COOKIE.getCookie(COOKIE.cookieName_id));
let options = new RequestOptions({ headers: headers, withCredentials:true });
return options;
}
}