1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using Bowin.Common.Utility;
- using Bowin.Common.Mail;
- using Bowin.Common.Log;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.SystemView;
- using EMIS.DataLogic.SystemDAL;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class MailVerifyServices : BaseServices, IMailVerifyServices
- {
- public UserDAL UserDAL { get; set; }
- public MailVerifyCodeDAL MailVerifyCodeDAL { get; set; }
- public void SendVerifyMail(string applicationPath, Guid userID, string email)
- {
- var user = UserDAL.UserRepository.GetSingle(x => x.UserID == userID, (x => x.Sys_MailVerifyCode));
- if (user == null) throw new Exception("验证码发送失败,无法找到该用户的信息。");
- string verifyCode = Guid.NewGuid().ToString().Replace("-", "");
- string title = "【验证邮件】欢迎使用教务信息管理系统";
- string content = user.Name + @",你好:<br><br>
- 感谢您使用教务信息管理系统,请点击以下链接完成你的验证操作:<br>
- <a href=""" + applicationPath + "/Common/UserVerify?Code=" + verifyCode + "&UserID=" + userID.ToString() + @""" target=""_blank"">"
- + verifyCode.ToUpper() + "</a>";
- try
- {
- MailHelper.SendMail(email, title, content);
- var userVerifyCode = MailVerifyCodeDAL.MailVerifyCodeRepository.GetSingle(x => x.UserID == userID);
- if (userVerifyCode != null)
- {
- UnitOfWork.Remove(userVerifyCode);
- }
- userVerifyCode = new Sys_MailVerifyCode()
- {
- UserID = userID,
- VerifyCode = verifyCode,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateTime = DateTime.Now,
- CreateUserID = userID,
- ModifyTime = DateTime.Now,
- ModifyUserID = userID
- };
- UnitOfWork.Add(userVerifyCode);
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw (ex);
- }
- }
- public bool Verify(Guid userID, string verifyCode)
- {
- var userVerifyCode = MailVerifyCodeDAL.MailVerifyCodeRepository.GetSingle(x => x.UserID == userID);
- if (userVerifyCode == null || userVerifyCode.VerifyCode.Trim() != verifyCode.Trim())
- {
- return false;
- }
- return true;
- }
- }
- }
|