public JObject send_activation_mail([FromBody] JObject value) { JObject returnObj = new JObject(); try { int USER_ID = int.Parse(value["USER_ID"].ToString()); String USER_EMAIL = value["USER_EMAIL"].ToString(); Classes.CodeGenerator codeGenerator = new Classes.CodeGenerator(); String activationCode = codeGenerator.ActivationCodeGenerator(); // saving in confirmation code table checkarr.Confirmationcode confirmationCodeModel = new checkarr.Confirmationcode(); confirmationCodeModel.ConfirmationCode = activationCode; confirmationCodeModel.ConfirmationType = "ACTIVATION_CODE"; confirmationCodeModel.GeneratedOn = DateTime.UtcNow; confirmationCodeModel.ExpiryTime = DateTime.UtcNow.AddDays(1); confirmationCodeModel.Used = "F"; confirmationCodeModel.UserId = USER_ID; homeDBContext.Confirmationcode.Add(confirmationCodeModel); homeDBContext.SaveChanges(); Classes.Token tokenGenerator = new Classes.Token(); JwtSecurityToken activationToken = tokenGenerator.GenerateActivationToken(USER_ID); // sending activation mail Classes.Mailer currentMailer = new Classes.Mailer(); currentMailer.sendActivationMail(USER_EMAIL, new JwtSecurityTokenHandler().WriteToken(activationToken), activationCode, USER_ID); returnObj.Add("RETURN_CODE", 1); // mail sent returnObj.Add("ACTIVATION_TOKEN", new JwtSecurityTokenHandler().WriteToken(activationToken)); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception in home controller while sending activation mail " + e); returnObj.Add("RETURN_CODE", 2); // exception; } return(returnObj); }
public JObject Account_recovery([FromBody] JObject value) { JObject returnObject = new JObject(); try { checkarr.checkarrContext registerDBContext = new checkarr.checkarrContext(); checkarr.UserLog Userr = registerDBContext.UserLog.FirstOrDefault(i => i.UserEmaill == value["RECOVERY_EMAIL"].ToString()); // query through database and store email in recovery_email_temp if (Userr == null) { returnObject.Add("RETURN_CODE", 2); returnObject.Add("RECOVERY_TOKEN", null); } else if (value["RECOVERY_EMAIL"].ToString() == Userr.UserEmaill) { // string gen_recoveryToken_tmp= JwtSecurityToken recoveryToken = new JwtSecurityToken(); recoveryToken = new Classes.Token().GenerateRecoveryToken(value["RECOVERY_EMAIL"].ToString()); Classes.CodeGenerator recovery_code_temp = new Classes.CodeGenerator(); string recoverycode_stringtemp = recovery_code_temp.RecoveryCodeGenerator(); //SAVE recoverycode_stringtemp TO TABLE CONFIRMATION CODES WITH TYPE "RECOVERY_CODE" checkarr.Confirmationcode newcode = new checkarr.Confirmationcode(); newcode.ConfirmationCode = recoverycode_stringtemp; newcode.ConfirmationType = "RECOVERY_CODE"; newcode.GeneratedOn = DateTime.UtcNow; newcode.ExpiryTime = DateTime.UtcNow.AddDays(1); newcode.Used = "F"; newcode.UserId = Userr.IduserLog; registerDBContext.Confirmationcode.Add(newcode); registerDBContext.SaveChanges(); Classes.Mailer mail_temp_obj = new Classes.Mailer(); mail_temp_obj.sendRecoveryMail(value["RECOVERY_EMAIL"].ToString(), new JwtSecurityTokenHandler().WriteToken(recoveryToken), recoverycode_stringtemp); returnObject.Add("RETURN_CODE", 1); returnObject.Add("RECOVERY_TOKEN", new JwtSecurityTokenHandler().WriteToken(recoveryToken)); } else { returnObject.Add("RETURN_CODE", 2); returnObject.Add("RECOVERY_TOKEN", null); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("EXCEPTION IN ACCOUNT RECOVERY = " + ex); returnObject.Add("RETURN_CODE", 3); returnObject.Add("RECOVERY_TOKEN", null); } /* * . RETURN_CODE: 1 = RECOVERY MAIL IS SENT * . RETURN_CODE: 2 = RECOVERY MAIL DOES NOT EXIST * . RETURN_CODE: 3 = EXCEPTION * */ return(returnObject); }