Skip to content
Snippets Groups Projects
Commit 526a3e23 authored by Farizki Kurniawan's avatar Farizki Kurniawan
Browse files

Merge branch 'dev' into 'main'

Dev

See merge request !4
parents 90778d6d 6ddb3c22
Branches
Tags
1 merge request!4Dev
...@@ -29,184 +29,206 @@ import javax.mail.internet.MimeMessage; ...@@ -29,184 +29,206 @@ import javax.mail.internet.MimeMessage;
import javax.mail.Authenticator; import javax.mail.Authenticator;
@WebService @WebService
public class SongsterImpl{ public class SongsterImpl {
@Resource @Resource
WebServiceContext context; WebServiceContext context;
@WebMethod @WebMethod
public String addSub( public String addSub(
@WebParam(name = "uid") Integer uid @WebParam(name = "uid") Integer uid) {
){
// String retval = ""; // String retval = "";
if(Auth.IsAccepted(context, "REST")){ if (Auth.IsAccepted(context, "PHP")) {
try{ try {
// autentikasi berhasil // autentikasi berhasil
String endpoint = "addSub"; String endpoint = "addSub";
String desc= "Request to add UID as a premium member"; String desc = "Request to add UID as a premium member";
Logger.log(context, desc, endpoint); Logger.log(context, desc, endpoint);
System.out.println("logged php yayayaa");
Subscription s = new Subscription();
s.init(); Subscription s = new Subscription();
s.init();
s.addSubscription(uid); s.addSubscription(uid);
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "add failed"; return "add failed";
} }
return retval + uid + " is now added"; return uid + " is now added";
} } else {
else{
return "unauthorized"; return "unauthorized";
} }
} }
@WebMethod @WebMethod
public int checkSub( public int checkSub(
@WebParam(name = "uid") Integer uid @WebParam(name = "uid") Integer uid) {
){
// log to db // log to db
String endpoint = "checkSub"; if (Auth.IsAccepted(context, "REST")) {
String desc= "Request to check premium status of UID"; String endpoint = "checkSub";
Logger.log(context, desc, endpoint); String desc = "Request to check premium status of UID";
Logger.log(context, desc, endpoint);
Subscription s = new Subscription();
s.init(); Subscription s = new Subscription();
int retval = 0; s.init();
try{ int retval = 0;
retval = s.checkExist(uid); try {
} catch (Exception e){ retval = s.checkExist(uid);
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
}
return retval; return retval;
} else {
return -1;
}
} }
@WebMethod @WebMethod
public String delSub( public String delSub(
@WebParam(name = "uid") Integer uid @WebParam(name = "uid") Integer uid) {
){
// log to db // log to db
String endpoint = "delSub";
String desc= "Request to delete UID from Premium";
Logger.log(context, desc, endpoint);
Subscription s = new Subscription();
s.init();
try{
s.delSubscription(uid);
} catch (Exception e){
e.printStackTrace();
}
return uid + " has been deleted"; if (Auth.IsAccepted(context, "REST")) {
String endpoint = "delSub";
String desc = "Request to delete UID from Premium";
Logger.log(context, desc, endpoint);
Subscription s = new Subscription();
s.init();
try {
s.delSubscription(uid);
} catch (Exception e) {
e.printStackTrace();
}
return uid + " has been deleted";
} else {
return "unauthorized";
}
} }
@WebMethod @WebMethod
public String editEmail( public String editEmail(
@WebParam(name = "uid") Integer uid, @WebParam(name = "uid") Integer uid,
@WebParam(name = "email") String email @WebParam(name = "email") String email) {
){
// log to db if (Auth.IsAccepted(context, "REST")) {
String endpoint = "editEmail"; // log to db
String desc= "Request to edit UID's email"; String endpoint = "editEmail";
Logger.log(context, desc, endpoint); String desc = "Request to edit UID's email";
Logger.log(context, desc, endpoint);
try{
Mailing m = new Mailing(); try {
m.init(); Mailing m = new Mailing();
m.editEmail(uid,email); m.init();
return "email has been added"; m.editEmail(uid, email);
} catch (Exception e){ return "email has been added";
e.printStackTrace(); } catch (Exception e) {
return "failed"; e.printStackTrace();
return "failed";
}
} else {
return "unauthorized";
} }
} }
@WebMethod @WebMethod
public String sendEmail( public String sendEmail(
@WebParam(name = "uid") Integer uid, @WebParam(name = "uid") Integer uid,
@WebParam(name = "msg") String msg @WebParam(name = "msg") String msg) {
){
// log to db // log to db
try{ if (Auth.IsAccepted(context, "REST")) {
String endpoint = "sendEmail"; try {
String desc= "Request send an email"; String endpoint = "sendEmail";
Logger.log(context, desc, endpoint); String desc = "Request send an email";
Logger.log(context, desc, endpoint);
Mailer mailer = new Mailer();
Mailer mailer = new Mailer();
Mailing m = new Mailing();
m.init(); Mailing m = new Mailing();
String targetemail = m.getEmail(uid); m.init();
if(targetemail==null || targetemail=="") return "no email found"; String targetemail = m.getEmail(uid);
mailer.mail("songster", targetemail, msg); if (targetemail == null || targetemail == "")
return "no email found";
return "email has been sent"; mailer.mail("songster", targetemail, msg);
} catch (Exception e){
e.printStackTrace(); return "email has been sent";
return "failed"; } catch (Exception e) {
e.printStackTrace();
return "failed";
}
} else {
return "unauthorized";
} }
} }
@WebMethod @WebMethod
public String getEmail( public String getEmail(
@WebParam(name = "uid") Integer uid @WebParam(name = "uid") Integer uid) {
){
// log to db // log to db
try{ if (Auth.IsAccepted(context, "REST")) {
String endpoint = "getEmail";
String desc= "Request email of UID"; try {
Logger.log(context, desc, endpoint); String endpoint = "getEmail";
String desc = "Request email of UID";
Logger.log(context, desc, endpoint);
Mailing m = new Mailing(); Mailing m = new Mailing();
m.init(); m.init();
String targetemail = m.getEmail(uid); String targetemail = m.getEmail(uid);
if(targetemail==null || targetemail=="") return "none"; if (targetemail == null || targetemail == "")
return "none";
return targetemail; return targetemail;
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "failed"; return "failed";
}
} else {
return "unauthorized";
} }
} }
@WebMethod @WebMethod
public String test( public String test(
@WebParam(name = "name") String name @WebParam(name = "name") String name) {
) { if (Auth.IsAccepted(context, "REST")) {
String to = "fariski.mail@gmail.com";
String from = "songstermailer@gmail.com"; String to = "fariski.mail@gmail.com";
String host = "smtp-relay.brevo.com"; String from = "songstermailer@gmail.com";
String host = "smtp-relay.brevo.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", host); Properties properties = System.getProperties();
properties.put("mail.smtp.port", "587"); properties.put("mail.smtp.host", host);
//properties.put("mail.smtp.ssl.enable", "true"); properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true"); // properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
//for mailing purposes
Session session = Session.getInstance(properties, new Authenticator(){ // for mailing purposes
protected PasswordAuthentication getPasswordAuthentication() { Session session = Session.getInstance(properties, new Authenticator() {
return new PasswordAuthentication("songstermailer@gmail.com", "bvWC3HhJ87DKcOg5"); protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("songstermailer@gmail.com", "bvWC3HhJ87DKcOg5");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("New Deals");
message.setText("In Songster, we have new deals coming through!");
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
} }
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("New Deals");
message.setText("In Songster, we have new deals coming through!");
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
}
return name + "received cah"; return name + "received cah";
} else {
return "unauthorized";
}
} }
} }
...@@ -12,6 +12,7 @@ public class Auth { ...@@ -12,6 +12,7 @@ public class Auth {
Map<String, List<String>> headers = (Map<String, List<String>>) Map<String, List<String>> headers = (Map<String, List<String>>)
context.getMessageContext().get(MessageContext.HTTP_REQUEST_HEADERS); context.getMessageContext().get(MessageContext.HTTP_REQUEST_HEADERS);
List<String> auth = headers.get("authorization"); List<String> auth = headers.get("authorization");
if(auth==null) return false;
if(auth.size()==0) return false; if(auth.size()==0) return false;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment