예제 #1
0
        public int UpdateUser(UserModels model, out string msg)
        {
            int ret = 0;

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

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

                data.comments     = model.Comments;
                data.condition    = clCondition.GetId(model.Condition);
                data.email        = model.Email;
                data.login        = model.Login;
                data.modifieddate = DateTime.Now;
                data.passwordsalt = CreateSalt();
                //      data.password = CreatePasswordHash(model.Password, data.passwordsalt);
                data.permission = clPermission.GetId(model.Permission);
                data.username   = model.UserName;

                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.Update(model.UserId, data, out msg);

                if (ret == 0)
                {
                    CAction clAction = new CAction(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());
                    clAction.AddAction(ActionType.EditUser, string.Format("Edit user {0}, {1}", data.username,
                                                                          data.login), out msg);
                }
            }
            catch (Exception ex) { msg = ex.Message; ret = -1; }

            return(ret);
        }
예제 #2
0
        public List <UserModels> GetListUser(STUserVP param)
        {
            List <UserModels> ret = new List <UserModels>();
            UserModels        item;
            List <STUser>     data = new List <STUser>();
            string            msg;
            CCondition        clCondition  = new CCondition();
            CPermission       clPermission = new CPermission();
            CUser             clUser;

            try
            {
                clUser =
                    new CUser(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());
                int retvalue = clUser.GetData(param, out data, out msg);

                foreach (STUser row in data)
                {
                    item            = new UserModels();
                    item.UserId     = row.userid;
                    item.UserName   = row.username;
                    item.Login      = row.login;
                    item.Comments   = row.comments;
                    item.Condition  = clCondition.GetName(row.condition);
                    item.Permission = clPermission.GetName(row.permission);
                    //  item.Password = row.password;
                    item.Email         = row.email;
                    item.OwnerUserId   = row.owneruserid;
                    item.OwnerUserName = row.ownerusername;
                    if (!row.isactivated)
                    {
                        item.AccountState = "Not activated";
                    }
                    else
                    {
                        item.AccountState = null;
                    }
                    ret.Add(item);
                }
            }
            catch (Exception ex) { msg = ex.Message; }
            return(ret);
        }
예제 #3
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);
        }