Exemplo n.º 1
0
        public bool SentLink(STUser stUser)
        {
            string msg = null;

            try
            {
                CUser  clUser = new CUser(stUser.userid, LocalData.CSDbUsers(), LocalData.LogPath());
                string key    = GenerateKey();
                int    ret    = clUser.SetKeyFPS(stUser.userid, key, out msg);
                if (ret != 0)
                {
                    return(false);
                }

                CMail clMail = new CMail(stUser.userid, LocalData.CSDbUsers(), LocalData.LogPath());

                STMail maildata = new STMail();
                maildata.to         = stUser.email;
                maildata.linkkey    = key;
                maildata.tamplate   = "MailToUserChangePassword.txt";
                maildata.fleetpwd   = null;
                maildata.pan        = null;
                maildata.dtcreate   = DateTime.Now.ToString("yyyyMMddHHmmss");
                maildata.dtmistsent = null;
                clMail.Insert(maildata, out msg);

                SMTPNotice smtp = new SMTPNotice(LocalData.SmtpHost(), LocalData.SmtpPort(), LocalData.SmtpUseSSL(),
                                                 LocalData.SmtpUserName(), LocalData.SmtpPassword(), LocalData.SmtpFrom(), LocalData.CSDbUsers(),
                                                 LocalData.LogPath(), LocalData.GetTemplatePath(), LocalData.Images());
                smtp.SendNotice(out msg);
            }
            catch (Exception ex) { msg = ex.Message; return(false); }

            return(true);
        }
Exemplo n.º 2
0
        public int AddUser(UserModels model, out string msg)
        {
            int    ret  = 0;
            STUser data = new STUser();

            msg = null;
            CCondition  clCondition  = new CCondition();
            CPermission clPermission = new CPermission();

            try
            {
                CUser clUser =
                    new CUser(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());

                ret = clUser.GetRecordByUserLogin(model.Login, out data, out msg);
                if (ret != 0)
                {
                    return(ret);
                }
                else
                {
                    if (data.login != null)
                    {
                        msg = "The login already exists in the database for the application.";
                        return(1);
                    }
                }

                data.comments      = model.Comments;
                data.activateddate = null;
                data.condition     = 0;
                data.creationdate  = DateTime.Now;
                data.email         = model.Email;
                data.isactivated   = false;
                data.login         = model.Login;
                data.modifieddate  = data.creationdate;
                data.owneruserid   = LocalData.UserId();
                //      data.passwordsalt = CreateSalt();
                //      data.password = CreatePasswordHash(model.Password, data.passwordsalt);
                data.permission    = clPermission.GetId(model.Permission);
                data.username      = model.UserName;
                data.passvaliddate = DateTime.Now.AddDays(-1);
                data.newemailkey   = GenerateKey();

                string[] arr = new[] { "'", "\"", "--" };
                if (CheckerField.CheckField(arr, data.comments, data.email, data.login, data.username))
                {
                    msg = "One or more fields contain invalid characters.";
                    return(2);
                }

                ret = clUser.Insert(data, out msg);

                if (ret == 0)
                {
                    CAction clAction = new CAction(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());
                    clAction.AddAction(ActionType.AddUser, string.Format("Add user {0}, {1}", data.username,
                                                                         data.login), out msg);

                    CMail clMail = new CMail(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());

                    STMail maildata = new STMail();
                    maildata.to         = data.email;
                    maildata.tamplate   = "MailToUserActivateAccount.txt";
                    maildata.linkkey    = data.newemailkey;
                    maildata.fleetpwd   = null;
                    maildata.pan        = null;
                    maildata.dtcreate   = DateTime.Now.ToString("yyyyMMddHHmmss");
                    maildata.dtmistsent = null;
                    maildata.login      = data.login;
                    clMail.Insert(maildata, out msg);

                    SMTPNotice smtp = new SMTPNotice(LocalData.SmtpHost(), LocalData.SmtpPort(), LocalData.SmtpUseSSL(),
                                                     LocalData.SmtpUserName(), LocalData.SmtpPassword(), LocalData.SmtpFrom(), LocalData.CSDbUsers(),
                                                     LocalData.LogPath(), LocalData.GetTemplatePath(), LocalData.Images());
                    smtp.SendNotice(out msg);
                }
            }
            catch (Exception ex) { msg = ex.Message; ret = -1; }
            return(ret);
        }