Exemple #1
0
        public void TestCurrentUserBoards1()
        {
            List <ClipboardModel> clipboards = new List <ClipboardModel>();

            for (int i = 1; i <= 500; ++i)
            {
                ClipboardModel board     = new ClipboardModel();
                string         boardName = "";
                for (int j = 0; j < i; ++j)
                {
                    boardName = boardName + "i";
                }
                board.board_name = boardName;
                board.id         = i;
                clipboards.Add(board);
            }

            UserLoginInfoModel login = new UserLoginInfoModel();

            login.id          = 1;
            login.inserted_at = null;
            login.username    = "******";

            CurrentUser user = new CurrentUser(login);

            user.SetClipboards(clipboards);
            String test = "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii";

            Assert.AreEqual(user.GetBoardId("iiiii"), 5);
            Assert.AreEqual(user.GetBoardId(test), test.Length);
            Assert.AreEqual(user.GetBoardId(""), -1);
            Assert.AreEqual(user.GetBoardId("iabcd"), -1);
        }
Exemple #2
0
        public void TestUserLoginInfoModel1()
        {
            UserLoginInfoModel model = new UserLoginInfoModel();

            Assert.IsNull(model.username);
            Assert.IsNull(model.inserted_at);
            Assert.AreEqual(model.id, -1);
        }
        /// <summary>
        /// Helper method to create a CurrentUser to test with
        /// </summary>
        /// <returns>
        /// Returns a CurrentUser instance with testable contents
        /// </returns>
        private CurrentUser CreateCurrentUser()
        {
            UserLoginInfoModel info = new UserLoginInfoModel();

            info.id          = 1;
            info.inserted_at = "";
            info.username    = "******";
            return(new CurrentUser(info));
        }
        public void TestAppWindow1()
        {
            //Note: App window does not have many testable methods
            UserLoginInfoModel info   = new UserLoginInfoModel();
            AppWindow          window = new AppWindow(info);

            Assert.IsNotNull(window);
            Assert.IsTrue(window is Window);
        }
Exemple #5
0
 public async Task <IActionResult> Create(UserLoginInfoModel model)
 {
     if (await IsValidUsernameAndPassword(model.username, model.password))
     {
         return(new ObjectResult(await GenerateToken(model.username)));
     }
     else
     {
         return(BadRequest());
     }
 }
Exemple #6
0
        public void TestCurrentUserGetPhone()
        {
            UserLoginInfoModel login = new UserLoginInfoModel();

            login.id          = -1;
            login.inserted_at = null;
            login.username    = "******";

            CurrentUser user = new CurrentUser(login);

            Assert.IsNull(user.GetPhoneNumber());
        }
Exemple #7
0
        public void TestUserLoginInfoModel2()
        {
            UserLoginInfoModel model = new UserLoginInfoModel();

            model.id          = 0;
            model.inserted_at = "x";
            model.username    = "******";

            Assert.AreEqual(model.id, 0);
            Assert.AreEqual(model.inserted_at, "x");
            Assert.AreEqual(model.username, "y");
        }
Exemple #8
0
        public bool ProcessRequest(IServiceContext context)
        {
            this.currentContext = context;

            if (context.Request.MethodName.Substring(0, 5) == "Login")
            {
                this.User           = new UserModel();
                this.User.LoginName = (string)context.Request.Parameters[0];
                this.User.LoginPwd  = (string)context.Request.Parameters[1];
                //Login2 方法为加密的登陆方法
                if (context.Request.MethodName == "Login2")
                {
                    this.User.LoginName = EncryptHelper.DesDecrypt(this.User.LoginName);
                    this.User.LoginPwd  = EncryptHelper.DesDecrypt(this.User.LoginPwd);
                }

                UserLoginInfoModel result = Login();
                if (result.LoginResult)
                {
                    //分配服务地址
                    DispatchService disp = new DispatchService();
                    disp.CurrentContext = context;
                    ServiceRegModel server = disp.DoDispatch();
                    //在外网测试有问提,暂时屏蔽 2012.5.24
                    result.ServiceUri = server.GetUri();

                    //如果登录成功,设置登录凭据
                    ServiceIdentity newUser = new ServiceIdentity();
                    newUser.Id              = result.User.UserID;
                    newUser.Name            = result.User.LoginName;
                    newUser.Expire          = new TimeSpan(0, 0, 20); //20秒过期,客户端必须订阅CheckUserIdentity 方法
                    newUser.IsAuthenticated = true;
                    newUser.Uri             = result.ServiceUri;
                    System.Diagnostics.Debug.WriteLine("--------------newUser.Uri={0} ; Client IP:{1}", newUser.Uri, context.Request.ClientIP);

                    ServiceAuthentication auth = new ServiceAuthentication(context);
                    //如果相同的用户账号已经在别的机器登录过,则取消之前的登录凭据
                    ServiceIdentity oldUser = auth.FindIdentity(newUser);
                    if (oldUser != null)
                    {
                        auth.SignOut(oldUser);
                    }

                    auth.Authenticate(newUser);
                }
                context.Response.WriteJsonString(result);

                return(false);
            }
            context.SessionRequired = true;
            return(true);
        }
Exemple #9
0
        public void TestCurrentUserCtor1()
        {
            UserLoginInfoModel login = new UserLoginInfoModel();

            login.id          = 1;
            login.inserted_at = "123-456-7899";
            login.username    = "******";

            CurrentUser user = new CurrentUser(login);

            Assert.AreEqual(user.GetUserId(), login.id);
            Assert.AreEqual(user.GetUsername(), login.username);
        }
Exemple #10
0
        //Url: //UserService/Login/string:LoginName;string:LoginPwd
        public UserLoginInfoModel Login()
        {
            string             message;
            UserBIZ            biz   = new UserBIZ();
            UserModel          user  = biz.Login(this.User.LoginName, EncryptPwd(this.User.LoginPwd), out message);
            UserLoginInfoModel model = new UserLoginInfoModel();

            model.User               = user;
            model.LoginResult        = user != null;
            model.LoginResultMessage = message;


            return(model);
        }
Exemple #11
0
        public void TestCurrentUserCtor2()
        {
            UserLoginInfoModel login = new UserLoginInfoModel();

            login.id          = -1;
            login.inserted_at = null;
            login.username    = "******";

            CurrentUser user = new CurrentUser(login);

            Assert.AreEqual(user.GetUserId(), login.id);
            Assert.AreEqual(user.GetPhoneNumber(), null);
            Assert.AreEqual(user.GetUsername(), login.username);
        }
 public static bool openToken(string token, out UserLoginInfoModel user)
 {
     user = null;
     try
     {
         byte[] data            = Convert.FromBase64String(token);
         string userInfoJsonStr = Encoding.UTF8.GetString(data);
         user = JsonConvert.DeserializeObject <UserLoginInfoModel>(userInfoJsonStr);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemple #13
0
        public LoginDataProviderTests()
        {
            var user = new UserLoginInfoModel {
                Username = Username, Password = PasswordHash, PasswordSalt = PasswordSalt
            };

            _usersDataAccessorMock.Setup(x => x.GetLoginInfo()).Returns(Extensions
                                                                        .GetDbSetMock(new List <UserLoginInfoModel> {
                user
            }.AsQueryable()).Object);

            _hashCreatorMock.Setup(x => x.Create(Username, Password, PasswordSalt)).Returns(PasswordHash);
            _tokenProviderMock.Setup(x => x.Get(user)).Returns(Token);

            _loginDataProvider = new LoginDataProvider(_usersDataAccessorMock.Object, _hashCreatorMock.Object, _tokenProviderMock.Object);
        }
Exemple #14
0
        public UserLoginInfoModel GetUserInfo(int UserID)
        {
            try
            {
                var objCrd = _unitofwork.UserMastersRepository.GetSingle(x => x.UserID == UserID && x.Active == true);

                if (objCrd != null)
                {
                    var objUserInfo = new UserLoginInfoModel
                    {
                        EmailID = objCrd.EmailID,
                        Role    = objCrd.Role,
                        UserID  = objCrd.UserID,
                    };
                    return(objUserInfo);
                }
            }
            catch { }
            return(null);
        }