public Response requestPasswordReset(Commoner commoner) { foreach (string account in new string[] { "users" }) { Response response = fetchRow(account, formatPairs(new KeyValue[] { new KeyValue("email", commoner.email) })); if (response.status_code == 1) { string urlToken = Utils.encryptPassword(Utils.randomString(90, true)); string resetPasswordLink = "https://proms.datachip.co.ke/account/resetpass/?urlToken=" + urlToken + "&origin=902"; response = insertRow("passresetrequests", new KeyValue[] { new KeyValue("code", Utils.randomNumber(11111, 99999).ToString()), new KeyValue("urlToken", urlToken), new KeyValue("email", commoner.email), new KeyValue("createdOn", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")) }); if (response.status_code == 1) { Email[] emailModels = new Email[] { new Email("Proms Datachip", commoner.email, null, "*****@*****.**", "Password reset link", "Hi,<br/>Click this <a href='" + resetPasswordLink + "'>Reset password link </a> to create your new password.") }; RequestService.post(null, "http://service.calista.co.ke/email/api/express-s2s.php", JsonConvert.SerializeObject(emailModels)); return(new Response(true, 1, "We have sent a reset password link to your email.", response.errors, null)); } return(new Response(true, 0, "Reset password request failed.", response.errors, null)); } } return(new Response(true, 0, "Reset password request failed.", new string[] { "No account associated with this email." }, null)); }
public Response makePayment(PaymentModel paymentModel, Commoner commoner) { switch (paymentModel.paymentMode) { case "MPesa-STK": return(makeSTKPush(paymentModel, commoner)); default: return(new Response(true, 0, "Failed.", new string[] { "Paymentmode not set." }, null)); } }
private static Response makeSTKPush(PaymentModel paymentModel, Commoner commoner) { STKPushResponse stkPushResponse = JsonConvert.DeserializeObject <STKPushResponse>((string)RequestService.post(null, "http://service.calista.co.ke/mpesa/api/stkpush/v1.php", JsonConvert.SerializeObject(new STKPush(paymentModel.mpesaPhone, paymentModel.amount, commoner.token, 5)))); switch (stkPushResponse.ResponseCode) { case 0: return(new Response(true, 1, "Success", null, stkPushResponse)); default: return(new Response(true, 0, "Failed", new string[] { stkPushResponse.ResponseDescription }, stkPushResponse)); } }
protected void Page_Load(object sender, EventArgs e) { string payLoad; using (var reader = new StreamReader(Request.InputStream)) payLoad = reader.ReadToEnd(); Commoner commoner = JsonConvert.DeserializeObject <Commoner>(payLoad); Response response = new AuthController().requestPasswordReset(commoner); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(JsonConvert.SerializeObject(response)); Response.End(); }
public Response resetPassword(string account, Commoner keyModel, Commoner updateModel) { Response response = updateRow(account, new KeyValue[] { new KeyValue("email", keyModel.email), }, new KeyValue[] { new KeyValue("password", Utils.encryptPassword(updateModel.password)), } ); if (response.status_code == 1) { return(new Response(true, 1, "Password reset successful.", null, null)); } return(new Response(true, 0, "Sign up failed.", response.errors, null)); }
protected void Page_Load(object sender, EventArgs e) { string payLoad; using (var reader = new StreamReader(Request.InputStream)) payLoad = reader.ReadToEnd(); Commoner commoner = JsonConvert.DeserializeObject <Commoner>(payLoad); Response response = new AccountController().update("users", new KeyValue[] { new KeyValue("email", commoner.email) }, new KeyValue[] { new KeyValue("password", Utils.encryptPassword(commoner.password)) } ); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(JsonConvert.SerializeObject(response)); Response.End(); }
public async static Task <IssueClasses.Issue> CreateTicket(string smsPhone, string account, string summary) { SearchResult <IssueClasses.Issue> search = await Commoner.GetOpenTicketsBySmsPhone(Project, IssueType, smsPhone, 1); if (search.total > 0) { return(search.issues.FirstOrDefault()); } var fields = new Dictionary <string, object> { { SmsPhoneField, smsPhone }, { RootField, account } }; var newIssue = JiraNewIssue.Create(Project, IssueType, summary, "", null); var issue = (await newIssue.ToJiraPost().PostIssueAsync(fields)).Value; return(issue); }
public Response signUp(string account, Commoner commoner) { Response response = insertRow(account, new KeyValue[] { new KeyValue("code", Utils.randomNumber(11111, 99999).ToString()), new KeyValue("token", Utils.encryptPassword(Utils.randomString(90, true))), new KeyValue("firstName", commoner.firstName), new KeyValue("lastName", commoner.lastName), new KeyValue("mobile", commoner.mobile), new KeyValue("email", commoner.email), new KeyValue("password", Utils.encryptPassword(commoner.password)), new KeyValue("avatar", commoner.avatar) }); if (response.status_code == 1) { return(signIn(new SignIn(commoner.email, commoner.password))); } return(new Response(true, 0, "Sign up failed.", response.errors, null)); }
public Response mpesaCallback(STKCallbackResponse stkCallbackResponse, Commoner getModel) { insertRow("callbacks", new KeyValue[] { new KeyValue("sktPushCallback", JsonConvert.SerializeObject(stkCallbackResponse)), new KeyValue("getData", JsonConvert.SerializeObject(getModel)) }); Commoner[] commoner = new Commoner[] { getModel }; commoner = JsonConvert.DeserializeObject <Commoner[]>(JsonConvert.SerializeObject(fetchRow("users", formatPairs(new KeyValue[] { new KeyValue("token", commoner[0].token) })).data)); Email[] emailModels = null; SmsMessage[] messageModels = null; switch (stkCallbackResponse.body.stkCallback.ResultCode) { case 0: /*Record payment*/ insertRow("payments", new KeyValue[] { new KeyValue("code", Utils.randomNumber(11111, 99999).ToString()), new KeyValue("docNo", "PRP-"), new KeyValue("transactionNo", stkCallbackResponse.body.stkCallback.CheckoutRequestID), new KeyValue("paymentTypeId", "1"), new KeyValue("paidId", ""), new KeyValue("crTypeId", commoner[0].roleId.ToString()), new KeyValue("crId", commoner[0].id.ToString()), new KeyValue("amount", "20"), new KeyValue("accountId", "1"), new KeyValue("timeStamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), new KeyValue("createdById", commoner[0].id.ToString()) }); /*Send email notifications*/ emailModels = new Email[] { new Email("Proms Datachip", commoner[0].email, null, "*****@*****.**", "New payment recieved", "Hi there, your payment has been recieved. From Proms by Datachip<hr/>") }; RequestService.post(null, "http://service.calista.co.ke/email/api/express-s2s.php", JsonConvert.SerializeObject(emailModels)); /* Send message notifications*/ messageModels = new SmsMessage[] { new SmsMessage(commoner[0].mobile, "Hi there, your payment has been recieved. From Proms by Datachip") }; return(JsonConvert.DeserializeObject <Response>((string)RequestService.post(null, "http://service.calista.co.ke/sms/api/express-s2s.php", JsonConvert.SerializeObject(messageModels)))); default: /*Send email notifications*/ emailModels = new Email[] { new Email("Proms Datachip", commoner[0].email, null, "*****@*****.**", "Payment failed", "Hi there, your payment has failed. " + stkCallbackResponse.body.stkCallback.ResultDesc + "<br/> From Proms by Datachip<hr/>") }; RequestService.post(null, "http://service.calista.co.ke/email/api/express-s2s.php", JsonConvert.SerializeObject(emailModels)); /* Send message notifications*/ messageModels = new SmsMessage[] { new SmsMessage(commoner[0].mobile, "Hi there, your payment has failed. From Proms by Datachip") }; return(JsonConvert.DeserializeObject <Response>((string)RequestService.post(null, "http://service.calista.co.ke/sms/api/express-s2s.php", JsonConvert.SerializeObject(messageModels)))); } }