Example #1
0
        public int ForgotPassword(ForgotPasswordRequest pForgotPasswordRequest)
        {
            IUserProfileRepository _IUserProfileRepository;
            _IUserProfileRepository = new UserProfileRepository(new WorkersInMotionDB());
            IGlobalUserRepository _IGlobalUserRepository;
            _IGlobalUserRepository = new GlobalUserRepository(new WorkersInMotionDB());
            string UserGUID = _IUserProfileRepository.GetUserIDFromEmail(pForgotPasswordRequest.Cred);
            GlobalUser globalUser = _IGlobalUserRepository.GetPasswordFromUserGUID(new Guid(UserGUID));
            if (globalUser != null)
            {
                EmailManager();
                //string url = AppDomain.CurrentDomain.BaseDirectory;
                //TextReader textreader = new StreamReader(url + "EmailTemplate.html");
                //string content = textreader.ReadToEnd();
                //content = content.Replace("$UserName$", globalUser.UserName);
                //content = content.Replace("$Password$", globalUser.Password);

                StringBuilder sbMailBody = new StringBuilder();
                sbMailBody.Append("<html>");
                sbMailBody.Append("<head></head>");
                sbMailBody.Append("<body>");
                sbMailBody.Append("<table cellspacing=\"2\" cellpadding=\"2\" border=\"0\" width=\"100%\">");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("Dear " + globalUser.UserName + ",");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("<b>User Name :</b>" + globalUser.UserName + "");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");

                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("<b>Password :</b>" + globalUser.Password + "");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("on WorkersInMotion Website");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");

                sbMailBody.Append("</table>");
                sbMailBody.Append("</body>");

                sbMailBody.Append("</html>");

                sftMail lMail = new sftMail(pForgotPasswordRequest.Cred, m_cSMTPUserName);
                lMail.FromDisplayName = string.Empty;
                lMail.FromAddress = m_cSMTPUserName;
                lMail.ToDisplayName = string.Empty;
                lMail.IsMailBodyHTML = true;
                lMail.MailSubject = "Password Recovery";
                lMail.MailBody = sbMailBody.ToString();
                lMail.SmtpHost = m_cSMTPHost;
                if (!string.IsNullOrEmpty(m_cPortNo))
                {
                    lMail.PortNo = Convert.ToInt32(m_cPortNo);
                }
                else
                {
                    lMail.PortNo = 25;
                }
                if (lMail.SendMail())
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return 401;
            }

        }
Example #2
0
 public CreateAccountResponse CreateAccount(LoginRequest pLoginRequest)
 {
     CreateAccountResponse CreateAccountResponse = new CreateAccountResponse();
     IUserRepository _IUserRepository;
     _IUserRepository = new UserRepository(new WorkersInMotionDB());
     IGlobalUserRepository _IGlobalUserRepository;
     _IGlobalUserRepository = new GlobalUserRepository(new WorkersInMotionDB());
     IUserProfileRepository _IUserProfileRepository;
     _IUserProfileRepository = new UserProfileRepository(new WorkersInMotionDB());
     int lRetVal = _IUserRepository.CheckUserName(pLoginRequest.UserName);
     if (lRetVal == 0)
     {
         GlobalUser _globalUser = new GlobalUser();
         _globalUser.UserGUID = Guid.NewGuid();
         _globalUser.UserName = pLoginRequest.UserName;
         _globalUser.Password = pLoginRequest.Password;
         _globalUser.Role_Id = _IGlobalUserRepository.GetRoleID("IND_C");
         _globalUser.IsActive = true;
         _globalUser.IsDelete = false;
         _globalUser.CreateDate = DateTime.UtcNow;
         _globalUser.CreateBy = _globalUser.UserGUID;
         _globalUser.LastModifiedDate = DateTime.UtcNow;
         _globalUser.LastModifiedBy = _globalUser.UserGUID;
         int result = _IGlobalUserRepository.InsertGlobalUser(_globalUser);
         //int result = _IGlobalUserRepository.Save();
         if (result > 0)
         {
             UserProfile _userProfile = new UserProfile();
             _userProfile.ProfileGUID = Guid.NewGuid();
             _userProfile.UserGUID = _globalUser.UserGUID;
             _userProfile.FirstName = _globalUser.UserName;
             _userProfile.LastModifiedDate = DateTime.UtcNow;
             _userProfile.LastModifiedBy = _globalUser.UserGUID;
             int resprofileInsert = _IUserProfileRepository.InsertUserProfile(_userProfile);
             //int resprofileInsert = _IUserProfileRepository.Save();
             if (resprofileInsert > 0)
             {
                 CreateAccountResponse.Role = 2;
                 CreateAccountResponse.UserGUID = _userProfile.UserGUID.ToString();
             }
             else
             {
                 _IGlobalUserRepository.DeleteGlobalUser(_globalUser.UserGUID);
                 //_IGlobalUserRepository.Save();
                 CreateAccountResponse = null;
             }
         }
         else
         {
             CreateAccountResponse = null;
         }
         return CreateAccountResponse;
     }
     else
     {
         return null;
     }
 }