MailVerifyServices.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Mail;
  8. using Bowin.Common.Log;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.SystemView;
  12. using EMIS.DataLogic.SystemDAL;
  13. namespace EMIS.CommonLogic.SystemServices
  14. {
  15. public class MailVerifyServices : BaseServices, IMailVerifyServices
  16. {
  17. public UserDAL UserDAL { get; set; }
  18. public MailVerifyCodeDAL MailVerifyCodeDAL { get; set; }
  19. public void SendVerifyMail(string applicationPath, Guid userID, string email)
  20. {
  21. var user = UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_MailVerifyCode));
  22. if (user == null) throw new Exception("验证码发送失败,无法找到该用户的信息。");
  23. string verifyCode = Guid.NewGuid().ToString().Replace("-", "");
  24. string title = "【验证邮件】欢迎使用鉴定考试报名管理系统";
  25. string content = user.Name + @",你好:<br><br>
  26. 感谢您使用鉴定考试报名管理系统,请点击以下链接进行密码修改:<br>
  27. <a href=""" + applicationPath + "/Common/UserVerify?Code=" + verifyCode + "&UserID=" + userID.ToString() + @""" target=""_blank"">"
  28. + verifyCode.ToUpper() + "</a>";
  29. try
  30. {
  31. MailHelper.SendMail(email, title, content);
  32. var userVerifyCode = MailVerifyCodeDAL.MailVerifyCodeRepository.GetSingle(x => x.UserID == userID);
  33. if (userVerifyCode != null)
  34. {
  35. UnitOfWork.Remove(userVerifyCode);
  36. }
  37. userVerifyCode = new Sys_MailVerifyCode()
  38. {
  39. UserID = userID,
  40. VerifyCode = verifyCode,
  41. RecordStatus = (int)SYS_STATUS.USABLE,
  42. CreateTime = DateTime.Now,
  43. CreateUserID = userID,
  44. ModifyTime = DateTime.Now,
  45. ModifyUserID = userID
  46. };
  47. UnitOfWork.Add(userVerifyCode);
  48. UnitOfWork.Commit();
  49. }
  50. catch (Exception ex)
  51. {
  52. throw (ex);
  53. }
  54. }
  55. public bool Verify(Guid userID, string verifyCode)
  56. {
  57. var userVerifyCode = MailVerifyCodeDAL.MailVerifyCodeRepository.GetSingle(x => x.UserID == userID);
  58. if (userVerifyCode == null || userVerifyCode.VerifyCode.Trim() != verifyCode.Trim())
  59. {
  60. return false;
  61. }
  62. return true;
  63. }
  64. }
  65. }