public IHttpActionResult PostEmployee(Employee employee) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (DBOperations.IsUsernameExist(employee.UserName)) { return(BadRequest("Username Already Exists")); } if (DBOperations.IsEmailExist(employee.Email_ID)) { return(BadRequest("Email ID Already Exists")); } employee.IsEmailVerified = false; string VerificationCode = Guid.NewGuid().ToString(); var userName = Encode.Base64Encode(employee.UserName); var link = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName); VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link); db.Employees.Add(employee); db.SaveChanges(); DBOperations.UpdateUserinfo(employee.ID, employee.UserName); CallStoredProc.RunLeaveEntryForNew(employee); return(Ok("Successfully Added")); } catch (Exception ex) { LogFile.WriteLog(ex); return(BadRequest()); } }
public IHttpActionResult PostEmployee(Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (DBOperations.IsUsernameExist(employee.UserName)) { return(Conflict()); } if (DBOperations.IsEmailExist(employee.Email_ID)) { return(Conflict()); } employee.IsEmailVerified = false; string VerificationCode = Guid.NewGuid().ToString(); var link = HttpContext.Current.Request.Url.AbsoluteUri + "/VerifyAccount/" + employee.UserName; VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link); db.Employees.Add(employee); db.SaveChanges(); CallStoredProc.RunLeaveEntryForNew(employee); return(Ok("Successfully Added")); }
/// <summary> /// Performs an activation of the verification link. /// </summary> /// <returns> /// If the link does not exist the method returns null. /// If the link is already activated the method returns false. /// If the link exists and was not activated the method returns true. /// </returns> public async Task <bool?> ActivateLinkAsync(string link) { try { var filter = new EqualityFilter <string>("link", link); VerificationLink verificationLink = (await verificationLinksDatabase.Get(filter)).FirstOrDefault(); if (verificationLink == null) { return(null); } if (verificationLink.Used) { return(false); } verificationLink.Used = true; await verificationLinksDatabase.Update(verificationLink, new[] { "Used" }); return(true); } catch (Exception ex) { exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration); throw new DatabaseException("Error occured while working with the database"); } }
public IHttpActionResult ForgotPassword(ForgotPassword pass) { var employee = DBOperations.IsEmployeeExist(pass.UserName); if (employee == null) { return(NotFound()); } else { string VerificationCode = Guid.NewGuid().ToString(); var link = HttpContext.Current.Request.Url.AbsoluteUri + "/ForgotPassword/" + employee.UserName; VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link, "ResetPassword"); return(Ok(employee)); } }
public async Task <string> CreateVerificationLinkAsync(UserInfo user) { try { VerificationLink link = new VerificationLink(user); await verificationLinksDatabase.Connect(); await verificationLinksDatabase.Insert(link); return(link.Link); } catch (Exception ex) { exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration); throw new DatabaseException("Error occured while working with the database"); } }
public IHttpActionResult ForgotPassword(ForgotPassword pass) { try { var employee = DBOperations.IsEmployeeExist(pass.UserName); if (employee == null) { return(NotFound()); } else { string VerificationCode = Guid.NewGuid().ToString(); var userName = Encode.Base64Encode(employee.UserName); var link = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName); VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link, "ResetPassword"); return(Ok("Reset Link has been sent to your mail id")); } } catch (Exception ex) { LogFile.WriteLog(ex); return(BadRequest()); } }