示例#1
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)));
            }
        }
示例#2
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);
        }