Example #1
0
        public AuthenticationResult Login(string username, string password)
        {
            AuthenticationResult result = new AuthenticationResult();

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                result.ErrorMessage = InvalidUserMessage;
                return(result);
            }

            var user = UserList.FirstOrDefault(x => x.Email.Equals(username.Trim(), StringComparison.OrdinalIgnoreCase) && x.Password.Equals(password));

            if (user is null)
            {
                result.ErrorMessage = InvalidUserMessage;
                return(result);
            }

            var claims = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, user.Name),
                new Claim(ClaimTypes.Email, user.Email),
                new Claim(ClaimTypes.Role, user.Role.ToString()),
            };

            result.IsAuthenticated = true;
            result.AccessToken     = JwtService.GenerateToken(claims);

            return(result);
        }
        //          ++++++++++ START PORTFOLIOS +++++++++++++

        // GET: UserProfile/PublicPortfolios
        public ActionResult PublicPortfolios(string username)
        {
            User        user = new User();
            UserProfile up   = new UserProfile()
            {
                Portfolio  = new Portfolio(),
                Portfolios = new PortfolioList(),
                User       = new User()
            };

            UserList users = new UserList();

            users.Load();
            up.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower());
            Guid ID = up.User.CheckIfUsernameExists(up.User.Username);

            if (ID != Guid.Empty)
            {
                up.User.LoadById(ID);
                up.Portfolios.LoadbyUser(up.User);
            }
            else
            {
            }
            return(View(up));
        }
Example #3
0
        // GET: PublicProjects
        public ActionResult PublicProjects(string username)
        {
            UserProfile up = new UserProfile()
            {
                Projects = new ProjectList(),
                User     = new User()
            };

            UserList users = new UserList();

            users.Load();
            up.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower());
            Guid ID = up.User.CheckIfUsernameExists(up.User.Username);

            if (ID != Guid.Empty)
            {
                up.Projects.LoadbyUserID(ID);
                up.User.LoadById(ID); //IDK if this is needed yet
            }
            else
            {
                //No user id was passed in!
            }
            return(View(up));
        }
Example #4
0
        // ==================== END EDIT =====================

        // ==================== START PUBLIC =====================

        // GET: PublicProject
        public ActionResult PublicProject(string username, string projectName)
        {
            User        user = new User();
            ProjectList pl   = new ProjectList();

            ScreenshotProjects sp = new ScreenshotProjects()
            {
                Project        = new Project(),
                Privacy        = new Privacy(),
                ScreenshotList = new ScreenshotList(),
                User           = new User(),
                Status         = new Status()
            };

            UserList users = new UserList();

            users.Load();
            sp.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower());
            Guid userId = user.CheckIfUsernameExists(sp.User.Username);

            pl.LoadbyUserID(userId);
            sp.Project = pl.FirstOrDefault(p => p.UrlFriendlyName == projectName.ToLower());

            if (sp.Project != null)
            {
                // Project doesnt exist
                sp.User.LoadById(userId);
                sp.ScreenshotList.LoadbyProjectID(sp.Project.Id);
            }
            else
            {
                //Project exists
            }
            return(View(sp));
        }
Example #5
0
        // GET: PublicProfile
        public ActionResult PublicProfile(string username)
        {
            UserProfile up = new UserProfile
            {
                Projects   = new ProjectList(),
                Portfolios = new PortfolioList(),
                User       = new User()
            };
            UserList users = new UserList();

            users.Load();
            up.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower());
            Guid idOfUser = up.User.CheckIfUsernameExists(up.User.Username);

            if (idOfUser != Guid.Empty)
            {
                up.User.LoadById(idOfUser);
            }
            //If the username doesn't exist, it's sent into the view with an invalid user with an empty guid and it will trigger a profile not found message.

            up.Projects.LoadbyUser(up.User);
            up.Portfolios.LoadbyUser(up.User);

            return(View(up));
        }
Example #6
0
        private static User LoadUser()
        {
            UserList users = new UserList();

            users.Load();
            User user = users.FirstOrDefault(p => p.Email == "*****@*****.**");

            return(user);
        }
Example #7
0
        public void LoadById()
        {
            UserList users = new UserList();

            users.Load();
            User user = new User();

            user.LoadById(users.FirstOrDefault(u => u.Email == "*****@*****.**").Id);

            Assert.AreEqual("Test", user.FirstName);
        }
Example #8
0
        public void DeleteTest()
        {
            UserList users = new UserList();

            users.Load();

            User user   = users.FirstOrDefault(c => c.FirstName == "Updated");
            int  actual = user.Delete();

            Assert.IsTrue(actual > 0);
        }
Example #9
0
        private void RemoveFriendButton_Clicked(object sender, EventArgs e)
        {
            Button b  = sender as Button;
            User   u2 = b.BindingContext as User;

            _service.RemoveFriendAsync(MainMenu.CurrentUser, u2);

            FriendsListView.ItemsSource = null;

            _friends.Remove(_friends.FirstOrDefault(u => u.Id == u2.Id));

            FriendsListView.ItemsSource = _friends;
        }
Example #10
0
        public void Delete()
        {
            UserList users = new UserList();

            users.Load();

            User user = new User();

            user.LoadById(users.FirstOrDefault(u => u.Email == "*****@*****.**").Id);

            int rowsAffected = user.Delete();

            Assert.IsTrue(rowsAffected == 1);
        }
Example #11
0
        public AdminWindowViewModel()
        {
            RunList = new ObservableCollection <Run>();

            IsTaskReadOnly   = true;
            IsUserReadOnly   = true;
            IsMarketReadOnly = true;

            SaveTaskCommand   = new SaveTaskCommand(this);
            SaveMarketCommand = new SaveMarketCommand(this);

            ChangeTaskCommand       = new ChangeTaskCommand(this);
            CancelSaveTaskCommand   = new CancelSaveTaskCommand(this);
            ContactDeveloperCommand = new ContactDeveloperCommand(this);
            ResetTaskCommand        = new ResetTaskCommand(this);

            CreateReportCommand = new CreateReportCommand(this);

            CloseCommand    = new CloseWindowCommand();
            MaximizeCommand = new MaximizeWindowCommand();
            MinimizeCommand = new MinimizeWindowCommand();

            CreateUserCommand = new CreateUserCommand(this);
            ChangeUserCommand = new ChangeUserCommand(this);
            SaveUserCommand   = new SaveUserCommand(this);
            CancelUserCommand = new CancelUserCommand(this);
            RemoveUserCommand = new RemoveUserCommand(this);

            TaskIndex   = 0;
            UserIndex   = 0;
            MarketIndex = 0;

            DevList = new List <User>(UserManager.GetUserByGroup(UserGroup.Dev, RunTimeContext.Context.DatabaseContext));

            MarketList = new ObservableCollection <Market>(MarketManager.GetAllMarkets(RunTimeContext.Context.DatabaseContext));
            TaskList   = new ObservableCollection <Task>(TaskManager.GetAllTasks(RunTimeContext.Context.DatabaseContext));
            SetUserList();

            SelectedTask   = TaskList.FirstOrDefault();
            SelectedUser   = UserList.FirstOrDefault();
            SelectedMarket = MarketList.FirstOrDefault();

            StartDate = DateTime.Now.AddMonths(-1);
            EndDate   = DateTime.Now;

            TaskFilter   = TaskList.FirstOrDefault();
            MarketFilter = MarketList.FirstOrDefault();
            DevFilter    = DevList.FirstOrDefault();
        }
Example #12
0
        public void UpdateTest()
        {
            UserList users = new UserList();

            users.Load();

            User user = users.FirstOrDefault(c => c.FirstName == "New");

            user.FirstName = "Updated";
            user.Update();

            user.LoadById();

            Assert.AreEqual(user.FirstName, "Updated");
        }
Example #13
0
        public Boolean addNewStaffMember(string firstname, string lastname, object userType, string pps, string phone, string email, int hod)
        {
            string userID = firstname + "." + lastname;

            // some validation on userID. No duplicate userIDs;
            //IUser duplicateUser = this.StaffList.FirstOrDefault(user => user.UserID == userID.Trim());

            //if (duplicateUser != null)
            //    return false;
            //else
            //{
            try
            {
                int    count = 0;
                string id    = userID;
                foreach (IUser user in UserList)
                {
                    if (user.FirstName.Equals(firstname) && user.LastName.Equals(lastname))
                    {
                        count++;
                    }
                }
                if (count == 1)
                {
                }
                else
                {
                    count--;
                    userID += count.ToString();
                }


                IStaff theUser = UserFactory.GetStaffMember(userID, hod, pps, email, phone, userType.ToString());

                IUser usernameDetails = UserList.FirstOrDefault(user => user.UserID == theUser.UserID);
                theUser.FirstName = usernameDetails.FirstName;
                theUser.LastName  = usernameDetails.LastName;

                StaffList.Add(theUser);                   // Add a reference to the newly created object to the Models UserList
                DataLayer.addNewStaffMemberToDB(theUser); //Gets the DataLayer to add the new user to the DB.
                return(true);
            }
            catch (System.Exception excep)
            {
                return(false);
            }
            //}
        }
Example #14
0
 private void LoadInitDataFromServer()
 {
     try
     {
         string message = string.Empty;
         UserList     = PharmacyDatabaseService.AllUsers(out message).OrderBy(r => r.Employee.Name).ToList();
         RoleList     = PharmacyDatabaseService.AllRoles(out message).ToList();
         SelectedUser = UserList.FirstOrDefault();//给个默认
     }
     catch (Exception ex)
     {
         ex = new Exception("获取用户或角色数据失败!", ex);
         Log.Error(ex);
         MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
 }
        // ----------------------------------- START PORTFOLIO ------------------------------------------


        // GET: PublicPortfolio
        public ActionResult PublicPortfolio(string username, string portfolioName)
        {
            User        user = new User();
            UserProfile up   = new UserProfile()
            {
                Portfolio  = new Portfolio(),
                Portfolios = new PortfolioList(),
                Projects   = new ProjectList(),
                Privacies  = new PrivacyList(),
                User       = new User()
            };

            UserList users = new UserList();

            users.Load();
            up.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower());
            Guid userId = user.CheckIfUsernameExists(up.User.Username);

            if (userId != Guid.Empty)
            {
                PortfolioList pl = new PortfolioList();
                pl.LoadbyUserID(userId);

                up.Portfolio = pl.FirstOrDefault(p => p.UrlFriendlyName == portfolioName.ToLower());

                if (up.Portfolio != null && up.Portfolio.Id != Guid.Empty)
                {
                    up.User.LoadById(userId);
                    up.Projects.LoadbyPortfolioID(up.Portfolio.Id);
                }
                else
                {
                    // Portfolio doesnt exit (cleaned portfolio name passed

                    // TO DO: ADD LOGIC FOR THIS?
                }
            }
            else
            {
                // Username passed doesnt exist (cleaned username passed)

                // TO DO: ADD LOGIC FOR THIS?
            }

            return(View(up));
        }
Example #16
0
        void Reset()
        {
            filter = new UserFilter();

            AddressCities       = new AddressCityList().Cities;
            SelectedAddressCity = AddressCities.FirstOrDefault();

            Users = new UserList(filter).Users;
            if (User.CurrentUser == null)
            {
                SelectedUser = Users.FirstOrDefault();
            }
            else
            {
                SelectedUser = User.CurrentUser;
            }
        }
Example #17
0
        /// <summary>
        /// Удаляет выбранного пользователя
        /// </summary>
        private void ShowAsseccQuestionWindow(object parameter)
        {
            if (MessageBox.Show(@"Вы действительно хотите удалить данных данного пользователя ?",
                                @"Подтверждение", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            CloseWindowCommand.Execute(null);

            using (var dataBase = new UserService())
            {
                dataBase.DeleteUser(User.Id);
            }

            var removedElement = UserList.FirstOrDefault(x => x.Id == User.Id);

            UserList.Remove(removedElement);
        }
        public FriendRequestsViewModel(FriendRequests friendRequests, tblUser userLogedIn)
        {
            view        = friendRequests;
            User        = userLogedIn;
            userService = new UserService();

            var listOfUsers = userService.GetUsers().Where(u => u.UserID != User.UserID).ToList();


            using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
            {
                tblUser userInDb = (from x in context.tblUsers
                                    where x.UserID == User.UserID
                                    select x).First();
                UserList = userInDb.tblUsers.ToList();
            }

            SelectedUser = UserList.FirstOrDefault();
        }
Example #19
0
        public void Insert()
        {
            UserList us = new UserList();

            us.Load();
            User user = us.FirstOrDefault(u => u.Email == "*****@*****.**");

            Portfolio portfolio = new Portfolio()
            {
                Description    = "Test",
                Name           = "Test",
                PortfolioImage = "Test",
                UserId         = user.Id
            };

            int rowsInserted = portfolio.Insert();

            Assert.IsTrue(rowsInserted == 1);
        }
Example #20
0
 public User GetUserByID(Guid userID)
 {
     return(UserList.FirstOrDefault((user) => user.ID == userID));
 }
Example #21
0
 void Find()
 {
     Users        = new UserList(filter).Users;
     SelectedUser = Users.FirstOrDefault();
 }
Example #22
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public User_Detail GetUser(int userId)
        {
            var model = UserList.FirstOrDefault(m => m.UserId == userId);

            return(model);
        }
Example #23
0
 public void RemoveUser(object user)
 {
     UserList.Remove(user as UserViewModel);
     SelectedUser = UserList.FirstOrDefault();
 }