protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridView1.DataBind(); // Sending Cancellation Confirmation Email To the Students for information try { String studentID; if (Session["StudentID"] == null) { studentID = "300717754"; } else { studentID = Session["StudentID"].ToString(); } EmailConfirmation obj = new EmailConfirmation(); DatabaseRegistration objdb = new DatabaseRegistration(); String emailID = objdb.getEmailID(studentID); String Subject = "Appointment Cancellation"; String body = "You have Successfully Cancelled Appointment.\n Message Send from Advisor Booking Service System"; obj.sendEmail("*****@*****.**", "Passwordisimportant", emailID, Subject, body); Server.Transfer("StudentCancelAppointment.aspx"); } catch { Server.Transfer("StudentCancelAppointment.aspx"); } }
protected void btnRegister_Click(object sender, EventArgs e) { try {String path; studentID = txtStudentID.Text; EmailConfirmation obj = new EmailConfirmation(); DatabaseRegistration objdb = new DatabaseRegistration(); if (objdb.isStudentIDAvailable(studentID) && objdb.isEmailIDAvailable(txtEmailID.Text)) { if (PhotoUpload.HasFile) { PhotoUpload.SaveAs(MapPath("~/Files/Images/Students/" + PhotoUpload.FileName)); path = PhotoUpload.FileName; ; } else { path = " "; } objdb.insert_Student_Info(txtStudentID.Text, txtFName.Text, txtLName.Text, ddlProgram.SelectedValue, txtCurrentSemester.Text, path); objdb.insert_Student_Login_Info(txtEmailID.Text, txtPassword.Text, txtStudentID.Text); String Subject = "Registration Confirmation Email"; String body = "You are Successfully registered with Advisor Booking Service."; body = body + "\n Now You can make an appointment with the advisor"; body = body + "\n Your User Name is =" + txtEmailID.Text; body = body + "\n Your Password is =" + txtPassword.Text; obj.sendEmail("*****@*****.**", "Passwordisimportant", txtEmailID.Text, Subject, body); lblMessage.Text = "Successfully Registered"; /// clear_Fields(); Response.Redirect("UserLogin.aspx"); } else { lblMessage.Text = "StudentID or Email ID is already registered"; clear_Fields(); } } catch (Exception obj) { lblMessage.Text = "Error in Registeration. Please try again"; } }
public HttpResponseMessage CreatePwdToken(ConfirmationCreateTokenModel model) { Api api = Api.INSTANCE; if (model.confirmation_url == null || model.email == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "password_reset_failed", error_description = "missing_fields" })); } // verify email syntax // To do: check if email address is disposable. try { var addr = new System.Net.Mail.MailAddress(model.email); } catch { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "password_reset_failed", error_description = "email_invalid" })); } using (var da = api.DAFactory.Get) { var user = da.Users.GetByEmail(model.email); if (user == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "password_reset_failed", error_description = "email_invalid" })); } EmailConfirmation confirm = da.EmailConfirmations.GetByEmail(model.email, ConfirmationType.password); // already awaiting a confirmation // to-do: resend? if (confirm != null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "confirmation_pending" })); } uint expires = Epoch.Now + EMAIL_CONFIRMATION_EXPIRE; // create new email confirmation string token = da.EmailConfirmations.Create(new EmailConfirmation { type = ConfirmationType.password, email = model.email, expires = expires }); // send confirmation email with generated token bool sent = api.SendPasswordResetMail(model.email, user.username, token, model.confirmation_url, expires); if (sent) { return(ApiResponse.Json(HttpStatusCode.OK, new { status = "success" })); } return(ApiResponse.Json(HttpStatusCode.OK, new { // success but email shitfaced status = "email_failed" })); } }
public HttpResponseMessage CreateUserWithToken(RegistrationUseTokenModel user) { Api api = Api.INSTANCE; if (user == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "invalid_token" })); } using (var da = api.DAFactory.Get) { EmailConfirmation confirmation = da.EmailConfirmations.GetByToken(user.token); if (confirmation == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "invalid_token" })); } var ip = ApiUtils.GetIP(Request); user.username = user.username ?? ""; user.username = user.username.ToLowerInvariant(); user.email = user.email ?? ""; user.key = user.key ?? ""; string failReason = null; if (user.username.Length < 3) { failReason = "user_short"; } else if (user.username.Length > 24) { failReason = "user_long"; } else if (!USERNAME_VALIDATION.IsMatch(user.username ?? "")) { failReason = "user_invalid"; } else if ((user.password?.Length ?? 0) == 0) { failReason = "pass_required"; } try { var addr = new System.Net.Mail.MailAddress(user.email); } catch { failReason = "email_invalid"; } if (failReason != null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "bad_request", error_description = failReason })); } if (!string.IsNullOrEmpty(api.Config.Regkey) && api.Config.Regkey != user.key) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "key_wrong", error_description = failReason })); } //has this ip been banned? var ban = da.Bans.GetByIP(ip); if (ban != null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "ip_banned" })); } //has this user registered a new account too soon after their last? var prev = da.Users.GetByRegisterIP(ip); if (Epoch.Now - (prev.FirstOrDefault()?.register_date ?? 0) < REGISTER_THROTTLE_SECS) { //cannot create a new account this soon. return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "registrations_too_frequent" })); } //create user in db var userModel = api.CreateUser(user.username, user.email, user.password, ip); if (userModel == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "user_exists" })); } else { //send OK email api.SendEmailConfirmationOKMail(user.username, user.email); da.EmailConfirmations.Remove(user.token); return(ApiResponse.Json(HttpStatusCode.OK, userModel)); } } }
public HttpResponseMessage CreateToken(ConfirmationCreateTokenModel model) { Api api = Api.INSTANCE; // smtp needs to be configured for this if (!api.Config.SmtpEnabled) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "smtp_disabled" })); } if (model.confirmation_url == null || model.email == null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "missing_fields" })); } // verify email syntax // To do: check if email address is disposable. try { var addr = new System.Net.Mail.MailAddress(model.email); } catch { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "email_invalid" })); } using (var da = api.DAFactory.Get) { // email is taken if (da.Users.GetByEmail(model.email) != null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "email_taken" })); } EmailConfirmation confirm = da.EmailConfirmations.GetByEmail(model.email, ConfirmationType.email); // already waiting for confirmation if (confirm != null) { return(ApiResponse.Json(HttpStatusCode.OK, new RegistrationError() { error = "registration_failed", error_description = "confirmation_pending" })); } uint expires = Epoch.Now + EMAIL_CONFIRMATION_EXPIRE; // create new email confirmation string token = da.EmailConfirmations.Create(new EmailConfirmation { type = ConfirmationType.email, email = model.email, expires = expires }); // send email with recently generated token bool sent = api.SendEmailConfirmationMail(model.email, token, model.confirmation_url, expires); if (sent) { return(ApiResponse.Json(HttpStatusCode.OK, new { status = "success" })); } return(ApiResponse.Json(HttpStatusCode.OK, new { status = "email_failed" })); } }
public async Task <IActionResult> ConfirmEmail([FromBody] EmailConfirmation confirmationData) => Ok(await _accountService.ConfirmEmailAsync(confirmationData.Id, confirmationData.Token));
public ResetPasswordValidator(IQueryEntities entities, IStorePasswords passwords) { CascadeMode = CascadeMode.StopOnFirstFailure; EmailConfirmation confirmation = null; RuleFor(p => p.Token) // token cannot be an empty guid .NotEmpty() .WithMessage(ValidateEmailConfirmation.FailedBecauseTokenWasEmpty, p => p.Token) // token must match a confirmation .Must(p => ValidateEmailConfirmation.TokenMatchesEntity(p, entities, out confirmation)) .WithMessage(ValidateEmailConfirmation.FailedBecauseTokenMatchedNoEntity, p => p.Token) ; RuleFor(p => p.Ticket) // ticket cannot be empty .NotEmpty() .WithMessage(ValidateEmailConfirmation.FailedBecauseTicketWasEmpty) ; RuleFor(p => p.Password) // cannot be empty .NotEmpty() .WithMessage(ValidatePassword.FailedBecausePasswordWasEmpty) // length must be between 6 and 100 characters .Length(passwords.MinimumPasswordLength, int.MaxValue) .WithMessage(ValidatePassword.FailedBecausePasswordWasTooShort(passwords.MinimumPasswordLength)) ; RuleFor(p => p.PasswordConfirmation) // cannot be empty .NotEmpty() .WithMessage(ValidatePassword.FailedBecausePasswordConfirmationWasEmpty) ; RuleFor(p => p.PasswordConfirmation) // must match password unless password is invalid or password confirmation is empty .Equal(p => p.Password) .Unless(p => string.IsNullOrWhiteSpace(p.PasswordConfirmation) || string.IsNullOrWhiteSpace(p.Password) || p.Password.Length < passwords.MinimumPasswordLength) .WithMessage(ValidatePassword.FailedBecausePasswordConfirmationDidNotEqualPassword) ; // when confirmation is not null, When(p => confirmation != null, () => { RuleFor(p => p.Token) // its intent must be to reset password .Must(p => confirmation.Intent == EmailConfirmationIntent.ResetPassword) .WithMessage(ValidateEmailConfirmation.FailedBecauseIntentWasIncorrect, p => confirmation.Intent, p => confirmation.Token) // it cannot be expired .Must(p => !confirmation.IsExpired) .WithMessage(ValidateEmailConfirmation.FailedBecauseIsExpired, p => confirmation.Token, p => confirmation.ExpiresOnUtc) // it cannot be retired .Must(p => !confirmation.IsRetired) .WithMessage(ValidateEmailConfirmation.FailedBecauseIsRetired, p => confirmation.Token, p => confirmation.RetiredOnUtc) // it must be redeemed .Must(p => confirmation.IsRedeemed) .WithMessage(ValidateEmailConfirmation.FailedBecauseIsNotRedeemed, p => confirmation.Token) // email address must be confirmed .Must(p => ValidateEmailAddress.IsConfirmed(confirmation.EmailAddress)) .WithMessage(ValidateEmailAddress.FailedBecauseIsNotConfirmed, p => confirmation.EmailAddress.Value) // it must be attached to a user .Must(p => ValidatePerson.UserIsNotNull(confirmation.EmailAddress.Person)) .WithMessage(ValidatePerson.FailedBecauseUserWasNull, p => confirmation.EmailAddress.Person.DisplayName) // user cannot have a saml account .Must(p => ValidateUser.EduPersonTargetedIdIsEmpty(confirmation.EmailAddress.Person.User)) .WithMessage(ValidateUser.FailedBecauseEduPersonTargetedIdWasNotEmpty, p => confirmation.EmailAddress.Person.User.Name) // user name must match local member account .Must(p => ValidateUser.NameMatchesLocalMember(confirmation.EmailAddress.Person.User.Name, passwords)) .WithMessage(ValidateUser.FailedBecauseNameMatchedNoLocalMember, p => confirmation.EmailAddress.Person.User.Name) ; RuleFor(p => p.Ticket) // its ticket must match the command ticket .Must(p => ValidateEmailConfirmation.TicketIsCorrect(confirmation, p)) .WithMessage(ValidateEmailConfirmation.FailedBecauseTicketWasIncorrect, p => p.Ticket, p => p.Token) ; }); }
private static Expression <Func <EmailConfirmation, bool> > ConfirmationEntity(EmailConfirmation entity) { Expression <Func <EmailConfirmation, bool> > entityBasedOn = e => e == entity ; return(entityBasedOn); }
public EmailController(IEmailService emailService, IEmailMessage message, IDataProtectionProvider provider, IConfiguration config, EmailAddress address, IBaseMongoRepository repository, EmailConfirmation emailConfirmation, Registration registration, ForgotPassword forgotPassword) { _repository = repository; _emailService = emailService; _message = message; _emailAddress = address; _protector = provider.CreateProtector("email"); _config = config; _registration = registration; _emailConfirmation = emailConfirmation; _forgotPassword = forgotPassword; }
public static void UpdateBOMExcelFile(string filePath, List <MaterialOrder> materialList) { string copyFilePath = filePath.ToLower().Replace(".xlsx", Defs.EXCEL_FILE_POSTFIX); bool retry = true; while (retry) { try { Util.DeleteFileIfExist(copyFilePath); File.Copy(filePath, copyFilePath, true); retry = false; } catch (Exception exc) { if (!(MessageBox.Show($"Verifique que el archivo no este siendo usado por otro usuario ({copyFilePath})", "Archivo siento utilizado", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)) { retry = false; } } } CurrentExcelOpenPath = copyFilePath; Excel.Application app = new Excel.Application(); app.WorkbookBeforeClose += CloseUpdatedExcel; Excel.Workbook workbook = app.Workbooks.Open(copyFilePath, UpdateLinks: 3); List <string> errorList = new List <string>(); foreach (Excel._Worksheet sheet in workbook.Sheets) { if (sheet.Visible == Excel.XlSheetVisibility.xlSheetHidden) { continue; } Excel.Range range = sheet.UsedRange; int rowCount = range.Rows.Count; int colCount = range.Columns.Count; List <Column> headercolumns = new List <Column>(colCount); string sheetName = sheet.Name.ToUpper(); if (sheetName == Defs.EXCLUDED_SHEET_COSTOS || sheetName == Defs.EXCLUDED_SHEET_LEYENDA) { continue; } Excel.Range rows = range.Rows; int rowToleranceIndex = 0; for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++) { if (headercolumns.Count < MIN_COLUMNS_BOM_AMOUNT) //Get Columns names { colCount = colCount > NORMAL_COLUMN_AMOUNT ? NORMAL_COLUMN_AMOUNT : colCount; for (int colIndex = 1; colIndex <= colCount; colIndex++) { if (range.Cells[rowIndex, colIndex] != null && range.Cells[rowIndex, colIndex].Value2 != null) { var colNameTemp = range.Cells[rowIndex, colIndex].Value2.ToString(); string columnName = Util.ConvertDynamicToString(colNameTemp); Column column = new Column(columnName, colIndex); headercolumns.Add(column); } } if (rowIndex == HEADER_COLUMN_TOLERANCE) { break; } } else { Column colMaterialCode = headercolumns.Find(col => Util.IsLike(col.Name, Defs.COL_MATERIAL_CODE)); Column colAmount = headercolumns.Find(col => Util.IsLike(col.Name, Defs.COL_AMOUNT)); if (colMaterialCode == null) { MessageBox.Show($"Formato no reconocido en {sheetName} en la columna de: Clave del material"); break; } var dynamicCode = range.Cells[rowIndex, colMaterialCode.Index].Value; var dynamicAmount = range.Cells[rowIndex, colAmount.Index].Value; string materialCode = Util.ConvertDynamicToString(dynamicCode); materialCode = Util.NormalizeString(materialCode); if (Util.IsEmptyString(materialCode)) { rowToleranceIndex++; if (EMPTINESS_ROW_TOLERANCE < rowToleranceIndex) { break; } } MaterialOrder material = materialList.Find(item => item.Code == materialCode); if (material == null) { continue; } double desiredAmount = Util.ConvertDynamicToDouble(dynamicAmount);; //Add Valid material to list if (!Util.IsEmptyString(materialCode) && desiredAmount != 0) { Column colStatus = headercolumns.Find(col => Util.IsLike(col.Name, Defs.COL_STATUS)); Column colUnit = headercolumns.Find(col => Util.IsLike(col.Name, Defs.COL_UNIT)); DeleteOverRowFromExcel(rows); double leftAmount = Math.Abs(desiredAmount - material.ChosenAmount); int currentRowIndex = rowIndex; int previousRowIndex = currentRowIndex - 1; int nextRowIndex = currentRowIndex + 1; //Add row upon try { rows[currentRowIndex].Insert(Excel.XlInsertShiftDirection.xlShiftDown, rows[currentRowIndex]); } catch (Exception e) { errorList.Add($"En la hoja: {sheetName} hubo un problema, posiblemente quedó incompleta, por favor revisarla"); workbook.Save(); continue; } Excel.Range currentLine = (Excel.Range)rows[nextRowIndex]; Excel.Range newLine = (Excel.Range)rows[currentRowIndex]; currentLine.Copy(newLine); range.Cells[currentRowIndex, colStatus.Index].Value = Defs.STATE_ORIGINAL; currentRowIndex++; previousRowIndex = currentRowIndex - 1; nextRowIndex = currentRowIndex + 1; if (desiredAmount > material.ChosenAmount) { range.Cells[currentRowIndex, colAmount.Index].Value = material.ChosenAmount; Excel.Range currentLineTemp = (Excel.Range)rows[currentRowIndex]; //Add row below try { rows[nextRowIndex].Insert(Excel.XlInsertShiftDirection.xlShiftDown, rows[currentRowIndex]); } catch (Exception e) { errorList.Add($"En la hoja: {sheetName} hubo un problema, posiblemente quedó incompleta, por favor revisarla"); workbook.Save(); continue; } Excel.Range newLineTemp = (Excel.Range)rows[nextRowIndex]; currentLineTemp.Copy(newLineTemp); range.Cells[nextRowIndex, colAmount.Index].Value = leftAmount; range.Cells[nextRowIndex, colStatus.Index].Value = Defs.STATE_PENDING; rowIndex++; } else { range.Cells[currentRowIndex, colAmount.Index].Value = material.ChosenAmount; } rows[currentRowIndex].Interior.Color = Color.Green; range.Cells[currentRowIndex, colStatus.Index].Value = Defs.STATE_RESERVED; range.Cells[currentRowIndex, colUnit.Index].Interior.Color = Color.Red; rows[previousRowIndex].Interior.Color = Color.White; range.Cells[currentRowIndex, colUnit.Index].Value = material.Unit; rowIndex++; materialList.Remove(material); } } } Marshal.ReleaseComObject(range); Marshal.ReleaseComObject(sheet); } if (errorList.Count != 0) { Util.ShowMessage(AlarmType.WARNING, errorList); } //cleanup GC.Collect(); GC.WaitForPendingFinalizers(); //close and release workbook.Save(); app.Visible = true; string excelName = workbook.Name; bool condition = !("Sheet1" == excelName); if (condition) { EmailConfirmation windows = new EmailConfirmation(CurrentExcelOpenPath); windows.Show(); } Marshal.ReleaseComObject(workbook); //quit and release //app.Quit(); Marshal.ReleaseComObject(app); }