// // GET: /Account/Register /* * public ActionResult Register() * { * return View(); * }*/ // // GET: /Account/Register public PartialViewResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { MembershipUser user = Membership.GetUser(model.Email, false); user.IsApproved = false; Membership.UpdateUser(user); owlas_0_0_1.Classes.Mailer mailer = new Classes.Mailer(); mailer.SendConfirmationEmail(user); /*FormsAuthentication.SetAuthCookie(model.Email, false createPersistentCookie );*/ return(PartialView("_RegisterReply")); } else { ModelState.AddModelError(model.Email, ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(PartialView("_RegisterReply")); }
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 Boolean Post([FromBody] Classes.User user) { if (user.Email != null && user.Password != null) { user.Email = user.Email.ToLower(); checkarr.checkarrContext registerDBContext = new checkarr.checkarrContext(); checkarr.UserLog UserRegister = registerDBContext.UserLog.FirstOrDefault(i => i.UserEmaill == user.Email); if (UserRegister != null) { // To be executed when user exists in the DB System.Diagnostics.Debug.Print("> User Exists"); return(false); } else { string temp_email; // To be executed when user doesn't exist in the DB UserRegister = new checkarr.UserLog(); UserRegister.UserFullname = user.Fullname; UserRegister.UserEmaill = user.Email; temp_email = user.Email; UserRegister.UserPassword = user.Password; UserRegister.UserSex = user.Gender; UserRegister.UserReg = DateTime.UtcNow; UserRegister.Activated = "F"; UserRegister.Disabled = "F"; // AuthRepository _authRepository = new AuthRepository(registerDBContext); /* have to make this await */ // _authRepository.Register(UserRegister, user.Password); //Adding user to the register context and saving that context registerDBContext.UserLog.Add(UserRegister); registerDBContext.SaveChanges(); Classes.Mailer currentMailer = new Classes.Mailer(); currentMailer.sendWelcomeMail(user.Email); /* * int newUserID; * // * // Id of last user * UserRegister = registerDBContext.UserLog.Last(); * if(temp_email == UserRegister.UserEmaill) * newUserID = UserRegister.IduserLog; * else * { * UserRegister = registerDBContext.UserLog.FirstOrDefault(i => i.UserEmaill == temp_email); * newUserID = UserRegister.IduserLog; * } * 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 = newUserID;// have to update user id * * registerDBContext.Confirmationcode.Add(confirmationCodeModel); * registerDBContext.SaveChanges(); * * * Classes.Token tokenGenerator = new Classes.Token(); * JwtSecurityToken activationToken = tokenGenerator.GenerateActivationToken(newUserID); * * * // sending activation mail * Classes.Mailer currentMailer = new Classes.Mailer(); * currentMailer.sendActivationMail(user.Email, new JwtSecurityTokenHandler().WriteToken(activationToken), activationCode); */ //System.Diagnostics.Debug.Print("===========================\n"); //System.Diagnostics.Debug.Print("Register POST\n"); //System.Diagnostics.Debug.Print("===========================\n"); //System.Diagnostics.Debug.Print("Fullname: " + user.Fullname + "\n"); //System.Diagnostics.Debug.Print("Email: " + user.Email + "\n"); //System.Diagnostics.Debug.Print("Password: "******"\n"); //System.Diagnostics.Debug.Print("Gender: " + user.Gender + "\n"); //System.Diagnostics.Debug.Print("===========================\n"); return(true); } // return false; } else { return(false); } }
// // GET: /Account/Register /* public ActionResult Register() { return View(); }*/ // // GET: /Account/Register public PartialViewResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { MembershipUser user = Membership.GetUser(model.Email, false); user.IsApproved = false; Membership.UpdateUser(user); owlas_0_0_1.Classes.Mailer mailer = new Classes.Mailer(); mailer.SendConfirmationEmail(user); /*FormsAuthentication.SetAuthCookie(model.Email, false createPersistentCookie );*/ return PartialView("_RegisterReply"); } else { ModelState.AddModelError(model.Email, ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return PartialView("_RegisterReply"); }
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); }