Exemplo n.º 1
0
        public UserModels GetUserByLogin(string login)
        {
            UserModels  ret  = new UserModels();
            STUser      data = new STUser();
            string      msg;
            CCondition  clCondition  = new CCondition();
            CPermission clPermission = new CPermission();

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

                ret            = new UserModels();
                ret.UserId     = data.userid;
                ret.UserName   = data.username;
                ret.Login      = data.login;
                ret.Comments   = data.comments;
                ret.Condition  = clCondition.GetName(data.condition);
                ret.Permission = clPermission.GetName(data.permission);
                //     ret.Password = data.password;
                //     ret.ConfirmPassword = ret.Password;
                ret.Email         = data.email;
                ret.OwnerUserId   = data.owneruserid;
                ret.OwnerUserName = data.ownerusername;
            }
            catch (Exception ex) { msg = ex.Message; }
            return(ret);
        }
Exemplo n.º 2
0
        public STUserVP GetParam(UserModelsViewParam prm)
        {
            STUserVP ret = new STUserVP();
            string   msg;

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

            try
            {
                ret.strdata = null;

                if (prm.UserName != null)
                {
                    ret.maskusername = prm.UserName;
                    ret.strdata     += string.Format("<UserName={0}>", ret.maskusername);
                }
                if (prm.Permission != null)
                {
                    ret.permission = clPermission.GetId(prm.Permission);
                    ret.strdata   += string.Format("<Permission={0}>", prm.Permission);
                }
                if (prm.Condition != null)
                {
                    ret.condition = clCondition.GetId(prm.Condition);
                    ret.strdata  += string.Format("<Condition={0}>", prm.Condition);
                }

                if (prm.Email != null)
                {
                    ret.maskemail = prm.Email;
                    ret.strdata  += string.Format("<Email={0}>", ret.maskemail);
                }

                if (prm.Login != null)
                {
                    ret.masklogin = prm.Login;
                    ret.strdata  += string.Format("<Login={0}>", ret.masklogin);
                }
                if (prm.IsAll)
                {
                    ret.isall = true;
                }
                else
                {
                    ret.isall = false;
                }
            }
            catch (Exception ex) { msg = ex.Message; }
            return(ret);
        }
Exemplo n.º 3
0
        public STUser GetLocalUser()
        {
            STUser      ret = new STUser();
            string      msg;
            CCondition  clCondition  = new CCondition();
            CPermission clPermission = new CPermission();

            try
            {
                CUser clUser   = new CUser(LocalData.UserId(), LocalData.CSDbUsers(), LocalData.LogPath());
                int   retvalue = clUser.GetRecordByUserId(LocalData.UserId(), out ret, out msg);
            }
            catch (Exception ex) { msg = ex.Message; }
            return(ret);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public UserModelsViewParam SetParam(STUserVP param)
        {
            UserModelsViewParam ret = new UserModelsViewParam();
            string msg;

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

            try
            {
                if (param.condition != null)
                {
                    ret.Condition = clCondition.GetName((int)param.condition);
                }
                else
                {
                    ret.Condition = null;
                }
                ret.Email = param.maskemail;
                ret.Login = param.masklogin;
                if (param.permission != null)
                {
                    ret.Permission = clPermission.GetName((int)param.permission);
                }
                else
                {
                    ret.Permission = null;
                }
                ret.UserName = param.maskusername;
                if (!param.isall)
                {
                    ret.IsAll = false;
                }
                else
                {
                    ret.IsAll = true;
                }
            }
            catch (Exception ex) { msg = ex.Message; }
            return(ret);
        }
Exemplo n.º 7
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);
        }