示例#1
0
 public UserModel(User user)
     : base(user)
 {
     if (user != null)
     {
         Age = user.Age;
         ApplicationCreated_Id = user.ApplicationCreated_Id;
         PasswordQuestion = user.PasswordQuestion;
         PasswordAnswer = user.PasswordAnswer;
         NickName = user.NickName;
         Name = user.Name;
         Email = user.Email;
         Country = user.Country;
         State = user.State;
         City = user.City;
         if (user.Gender.HasValue)
         {
             Gender = user.Gender.Value ? 1 : 0;
         }
         else
         {
             Gender = 1;
         }
         LastLoginTime = user.LastLoginTime;
         Id = user.Id;      
         Image_Id = user.Image_Id;
     }
 }
示例#2
0
 public UserViewModel(User usr)
     : base(usr)
 {
     name.SetValue(usr.Name);
     nickName.SetValue(usr.NickName);
     email.SetValue(usr.Email);
     passwordQuestion.SetValue(usr.PasswordQuestion);
     passwordAnswer.SetValue(usr.PasswordAnswer);
     gender.SetValue(usr.Gender.HasValue ? usr.Gender.Value : false);
     lastLoginTime.SetValue(usr.LastLoginTime.HasValue ? usr.LastLoginTime.Value : DateTime.Now);
     age.SetValue(usr.Age.HasValue ? usr.Age.Value : 0);
     password.SetValue(usr.Password);
     IsInitialized = false;
 }
        public void Register(string account, string pwd, int sex)
        {
            User newUser = ApplicationVM.ChatClient.Register(UserId, account, Utility.GetMD5String(pwd), sex);
            if (newUser != null)
            {
                if (newUser.Image_Id.HasValue)
                {
                    Image img = ApplicationVM.ChatClient.GetImage(newUser.Image_Id.Value);
                    var imgVM = ApplicationVM.AddImage(img);
					File.WriteAllBytes(imgVM.GetAbsoluteFile(true), img.TheImage);
                }
                user = newUser;
                ErrorMessage = string.Format(Resource.Messages.RegisterSucceeded, user.Id);
            }
            else
            {
                user = null;
                ErrorMessage = Resource.Messages.RegisterFailed;
            }
        }
示例#4
0
 public ClientUserModel(User user, UserApplicationInfo userInfo)
     : base(user)
 {
     if (userInfo != null)
     {
         Application_Id = userInfo.Application_Id;
         User_Id = userInfo.User_Id;
         if (userInfo.AgentMoney.HasValue)
             AgentMoney = userInfo.AgentMoney;
         else
             AgentMoney = 0;
         if (userInfo.Money.HasValue)
             Money = userInfo.Money;
         else
             Money = 0;
         if (userInfo.Score.HasValue)
             Score = userInfo.Score;
         else
             Score = 0;
         Role_Id = userInfo.Role_Id;
     }
 }
示例#5
0
 public User AddUser(int appid, int userId, string token, User user)
 {
     try
     {
         CheckToken(appid, userId, token);
         CheckCommand(appid, user.ApplicationCreated_Id, userId, BuiltIns.DefineUserCommand.Id, BuiltIns.AllRole.Id);
         modelAccesser.Add(user);
         return user;
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
示例#6
0
        public bool EnterRoom(int roomId, User user)
        {
            if (userCache.ContainsKey(roomId))
            {
				var info = client.GetUserInfo(user.Id);
                OperationContext.Current.Channel.Faulted += Channel_Faulted;
                this.unc = new UserNCallback { User = user, RoomId = roomId, Callback = OperationContext.Current.GetCallbackChannel<IRoomServiceCallback>(), UserInfo = info };
				userCache[roomId][user.Id] = unc;
                BroadCast(roomId, (u) => u.Callback.UserEnteredRoom(roomId, unc.User),user.Id);
                return true;
            }
            return false;
        }
 public bool UpdateUser(User user)
 {
     if (unc.User.Id == user.Id)
     {
         unc.User = user;
         dataServiceClient.UpdateUser(unc.User.Id, unc.DataServiceToken, user);
     }
     return true;
 }
示例#8
0
 public void UpdateUser(int appid, int userId, string token, User user)
 {
     try
     {
         CheckToken(appid, userId, token);
         if (userId != user.Id)
         {
             CheckCommand(appid, BuiltIns.AllApplication.Id, userId, BuiltIns.DefineUserCommand.Id, BuiltIns.AllRole.Id);
         }
         modelAccesser.Update(user);
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
示例#9
0
 public void UpdateUserProfileInfo(int appid, User user, string token, Image img)
 {
     try
     {
         using (TransactionScope scope = new TransactionScope())
         {
             UpdateUser(appid, user.Id, token, user);
             UpdateImage(appid, user.Id, token, img);
             scope.Complete();
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
示例#10
0
 public string ResetPassword(int appid, int userId, string token, int id)
 {
     try
     {
         CheckToken(appid, userId, token);
         User user = new User { Id = id };
         modelAccesser.Get<User>(user);
         user.Password = Utility.GetMD5String(id.ToString());
         modelAccesser.Update<User>(user);
         return id.ToString();
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
示例#11
0
 public YoYoStudio.Model.Core.User AddUser(int userId, string token, YoYoStudio.Model.Core.User user)
 {
     return(client.AddUser(application_Id, userId, token, user));
 }
示例#12
0
 public void UpdateUser(int userId, string token, YoYoStudio.Model.Core.User user)
 {
     client.UpdateUser(application_Id, userId, token, user);
 }
示例#13
0
 private void Login(string userId, string pwd, ref User usr)
 {
     try
     {
         var mac = Utility.GetMacAddress();
         int r = hallVM.ApplicationVM.ChatClient.CanUserLogin(int.Parse(userId), mac);
         if (r == 0)
         {
             usr = hallVM.ApplicationVM.ChatClient.Login(int.Parse(userId), pwd, mac);
             if (usr == null)
             {
                 MessageBox.Show(Messages.InvalidToken, Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
         else
         {
             usr = null;
             List<BlockType> types = hallVM.ApplicationVM.ChatClient.GetBlockTypes().ToList();
             string blockName = types.FirstOrDefault<BlockType>(t => t.Id == r).Name;
             MessageBox.Show(string.Format(Messages.UserBlocked, blockName), Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (TimeoutException exception)
     {
         hallVM.ApplicationVM.Logger.Debug("Login fail: " + exception.Message);
         usr = null;
         MessageBox.Show("登录超时", Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (FaultException exception)
     {
         hallVM.ApplicationVM.Logger.Debug("Login fail: " + exception.Message);
         usr = null;
         MessageBox.Show("登录失败", Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (CommunicationException exception)
     {
         hallVM.ApplicationVM.Logger.Debug("Login fail: " + exception.Message);
         usr = null;
         MessageBox.Show("登录失败", Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
     }
     catch (Exception)
     {
         usr = null;
         MessageBox.Show(Messages.InvalidToken, Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
示例#14
0
        private void LogonButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(AccountTextBox.Text) || string.IsNullOrEmpty(PwdPasswordBox.Password))
            {
                MessageBox.Show("用户名和密码不能为空!", Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            bool rememberPwd = RememberPwdCheckBox.IsChecked.HasValue?RememberPwdCheckBox.IsChecked.Value:false;
            bool autoLogin = AutoLogonCheckBox.IsChecked.HasValue?AutoLogonCheckBox.IsChecked.Value:false;

            this.TopGrid.Cursor = Cursors.Wait;
            User usr = null;
            try
            {
                Login(AccountTextBox.Text.Trim(), PwdPasswordBox.Password.Trim(), ref usr);
            }
            catch
            {
                MessageBox.Show(Messages.LoginFailed, Text.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                this.TopGrid.Cursor = Cursors.Arrow;
            }

            if (usr != null)
            {
                PART_Busy.Visibility = System.Windows.Visibility.Visible;
                PART_Login.Visibility = System.Windows.Visibility.Collapsed;
                hallVM.ApplicationVM.StartUp();
                currentUser = usr;
                hallVM.ApplicationVM.HallWindowVM.Notify<UserViewModel>(() => hallVM.Me);
                hallVM.ApplicationVM.IsAuthenticated = true;
                hallVM.UpdateLoginInfo(AccountTextBox.Text.Trim(), PwdPasswordBox.Password.Trim(), rememberPwd, HeaderImage.Source==null?string.Empty:HeaderImage.Source.ToString(), autoLogin);
                hallVM.Notify<bool>(() => hallVM.IsAuthenticated);
            }
            else
            {
                this.TopGrid.Cursor = Cursors.Arrow;
            }
        }
示例#15
0
 public User GetUser(int appid, int userId, string token, int id)
 {
     try
     {
         CheckToken(appid, userId, token);
         User user = new User { Id = id };
         modelAccesser.Get(user);
         return user.Loaded ? user : null;
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
示例#16
0
		public UserViewModel(User usr):base(usr)
		{
            Name = usr.Name;
            NickName = usr.NickName;            
        }
示例#17
0
 private string GetUserToken(User user, string password, int appId)
 {
     TokenCache tc = new TokenCache { Application_Id = appId, User_Id = user.Id };
     modelAccesser.Get(tc);
     if (user.IsBuiltIn)
     {
         if (tc.Loaded)
         {
             return tc.Token;
         }
     }
     string rawToken = user.Id.ToString() + ClientAddress + password + Guid.NewGuid().ToString();
     byte[] rawTokenBytes = System.Text.UTF8Encoding.Default.GetBytes(rawToken);
     string token = Convert.ToBase64String(rawTokenBytes);
     tc.Token = token;
     if (tc.Loaded)
     {
         modelAccesser.Update(tc);
     }
     else
     {
         modelAccesser.Add(tc);
     }
     return token;
 }
 private void UserEnteredRoomEventHandler(int arg1, User arg2)
 {
     if (RoomVM.Id == arg1)
     {
         UserEntered(arg2, true);
     }
 }
示例#19
0
        public User Register(int appid, int userId, string account, string pwd, int sex)
        {
            try
            {
                User newUser = null;
                using (TransactionScope scope = new TransactionScope())
                {
                    var userIdList = new UserIdList { Application_Id = appid, User_Id = userId };
                    modelAccesser.Get(userIdList);
                    if (!userIdList.Loaded)
                    {
                        userIdList.Application_Id = BuiltIns.AllApplication.Id;
                        userIdList.User_Id = userId;
                        modelAccesser.Get(userIdList);
                    }
                    if (userIdList.Loaded)
                    {
                        userIdList.IsUsed = true;
                        modelAccesser.Update<UserIdList>(userIdList);

                        newUser = new User { Id = userId, ApplicationCreated_Id = appid, Name = account, NickName = account, Password = pwd, Gender = sex == 0 };
                        modelAccesser.Add<User>(newUser);
                        UserApplicationInfo userInfo = new UserApplicationInfo { Application_Id = appid, Role_Id = BuiltIns.RegisterUserRole.Id, User_Id = userId, Money = 0, AgentMoney = 0, Score = 0 };
                        modelAccesser.Add<UserApplicationInfo>(userInfo);
                    }
                    scope.Complete();
                }

                return newUser;
            }
            catch (Exception)
            {
                throw new DatabaseException();
            }
        }
 public void UpdateUserProfileInfo(User user, string token, Image img)
 {
     client.UpdateUserProfileInfo(application_Id, user, token, img);
 }
示例#21
0
 public string Login(int appid, int userId, string password)
 {
     try
     {
         string token = string.Empty;
         User user = new User { Id = userId };
         modelAccesser.Get<User>(user);
         if (user.Loaded)
         {
             if ((user.Password == password) || (user.Password == Utility.GetMD5String(password)))
             {
                 token = GetUserToken(user, password, appid);
                 logger.Debug("Login OK : AppId - " + appid + " , UserId - " + userId + " , Token - " + token);
             }
         }
         logger.Debug("Exit Login : AppId - " + appid + " , UserId - " + userId);
         return token;
     }
     catch (Exception ex)
     {
         logger.Error("Login Error: AppId - " + appid + " , UserId - " + userId, ex);
         throw new DatabaseException();
     }
 }
 private void UserEntered(User user, bool notify)
 {
     UserViewModel uvm = null;
     if (!ApplicationVM.LocalCache.AllUserVMs.ContainsKey(user.Id))
     {
         uvm = new UserViewModel(user);
         uvm.Initialize();
         ApplicationVM.LocalCache.AllUserVMs.Add(user.Id, uvm);
     }
     else
     {
         uvm = ApplicationVM.LocalCache.AllUserVMs[user.Id];
         if (!uvm.IsInitialized)
             uvm.Initialize();
     }
     lock (UserVMs)
     {
         uvm.RoomWindowVM = this;
         if (!UserVMs.Contains(uvm))
         {
             UserVMs.Add(uvm);
         }
     }
     if (notify)
     {
         CallJavaScript("UserEntered", uvm.GetJson(false));
     }
 }
 void UserLoggedInEventHandler(User obj)
 {
     if (!ApplicationVM.LocalCache.AllUserVMs.ContainsKey(obj.Id))
     {
         UserViewModel uvm = new UserViewModel(obj);
         ApplicationVM.LocalCache.AllUserVMs.Add(obj.Id, uvm);
     }
     OnlinieUserCount++;
 }
示例#24
0
 public bool UpdateUser(YoYoStudio.Model.Core.User user)
 {
     return(base.Channel.UpdateUser(user));
 }