Beispiel #1
0
        public IActionResult Login(RZDMonitoringModel model, string login, string password)
        {
            try
            {
                if (login == null)
                {
                    login = "";
                }
                if (password == null)
                {
                    password = "";
                }

                if (login == "" && password == "")
                {
                    login    = "******";
                    password = "******";
                }

                MUser user = model.SelectFirst <MUser>($"select * from [MUser] (nolock) where Login={model.AddParam(login)}");
                if (user != null)
                {
                    if (user.PassCode == MFunc.GetSecurityHash(password))
                    {
                        model.AddUser(user, login);
                        SetAuth(login);
                    }
                    else
                    {
                        throw new NotAuthException($@"Неправильный пароль...");
                    }
                }
                else
                {
                    throw new NotAuthException($@"Пользователь ""{login}"" не найден...");
                }

                return(Json(new MJsonResult(MJsonResultType.OK, null)));
            }
            catch (Exception e)
            {
                return(Json(new MJsonResult(MJsonResultType.Error, e.Message)));
            }
        }
Beispiel #2
0
        public override void InitUser(string login, string name, string password)
        {
            MUser user = SelectFirst <MUser>($"select * from MUser where Login={AddParam(login)}");

            if (user == null)
            {
                user       = this.CreateObject(typeof(MUser)) as MUser;
                user.Login = login;
                user.Fio   = name;
                if (login == "madmin")
                {
                    user.IsAdmin = true;
                }
            }
            if (user.PassCode == 0)
            {
                user.PassCode = MFunc.GetSecurityHash(password);
            }
            Save(null);
        }
Beispiel #3
0
        public override void InitUser(string login, string name, string password)
        {
            MEntity entity = SelectFirst <MEntity>($"select * from MEntity where EntityTypeId='USR' and code={AddParam(login)}");

            if (entity == null)
            {
                entity              = MainDic.GetObj <MEntity>(null);
                entity.Code         = login;
                entity.Name         = name;
                entity.EntityTypeId = "USR";
            }

            MPassword pass = SelectFirst <MPassword>($"select * from MPassword where Id={AddParam(login)}");

            if (pass == null)
            {
                pass          = MainDic.GetObj <MPassword>(login);
                pass.PassCode = MFunc.GetSecurityHash(password);
            }
            Save(null);
        }
Beispiel #4
0
        public IActionResult Login(MBuilderModel model, string login, string password)
        {
            try
            {
                if (login == null)
                {
                    login = "";
                }
                if (password == null)
                {
                    password = "";
                }

                if (login == "" && password == "")
                {
                    login    = "******";
                    password = "******";
                }

                MEntity   user = model.SelectFirst <MEntity>($"select * from [MEntity] (nolock) where EntityTypeId='USR' and Code={model.AddParam(login)}");
                MPassword pass = model.SelectFirst <MPassword>($"select * from [MPassword] (nolock) where Id={model.AddParam(login)} and PassCode={model.AddParam(MFunc.GetSecurityHash(password))}");
                if (user != null)
                {
                    if (pass != null)
                    {
                        model.AddUser(new MUser(user), login);
                        SetAuth(login);
                    }
                    else
                    {
                        throw new NotAuthException($@"Неправильный пароль...");
                    }
                }
                else
                {
                    throw new NotAuthException($@"Пользователь ""{login}"" не найден...");
                }

                return(Json(new MJsonResult(MJsonResultType.OK, null)));
            }
            catch (Exception e)
            {
                return(Json(new MJsonResult(MJsonResultType.Error, e.Message)));
            }
        }