/// <summary>
        /// Get the list of all users in the organization.
        /// </summary>
        /// <param name="parameters">The parameters is the Dictionary object which conrains the filters in the form of key,value pair to refine the list.<br></br>The possible filters are listed below<br></br>
        /// <table>
        /// <tr><td>filter_by</td><td>Filter through users with user status.<br></br>Allowed Values: <i>Status.All, Status.Active, Status.Inactive, Status.Invited</i> and <i>Status.Deleted</i></td></tr>
        /// <tr><td>sort_column</td><td>Sort users.<br></br>Allowed Values: <i>name, email, user_role</i> and <i>status</i></td></tr>
        /// </table>
        /// </param>
        /// <returns>UserList object.</returns>
        public UserList GetUsers(Dictionary <object, object> parameters)
        {
            string url      = baseAddress;
            var    response = ZohoHttpClient.get(url, getQueryParameters(parameters));

            return(UserParser.getUserList(response));
        }
Example #2
0
        /// <summary>
        ///     Send invitation email to a user.
        /// </summary>
        /// <param name="user_id">The user_id is the identifier of the user.</param>
        /// <returns>System.String.<br></br>The success message is "Your invitation has been sent."</returns>
        public string InviteUser(string user_id)
        {
            var url      = baseAddress + "/" + user_id + "/invite";
            var response = ZohoHttpClient.post(url, getQueryParameters());

            return(UserParser.getMessage(response));
        }
        /// <summary>
        /// Mark an active user as inactive.
        /// </summary>
        /// <param name="user_id">The user_id is the identifier of the user.</param>
        /// <returns>System.String.<br></br>The success message is "The user has been marked as inactive."</returns>
        public string MarkAsInactive(string user_id)
        {
            string url      = baseAddress + "/" + user_id + "/inactive";
            var    response = ZohoHttpClient.post(url, getQueryParameters());

            return(UserParser.getMessage(response));
        }
Example #4
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            UserParser     parser         = new UserParser();

            if (openFileDialog.ShowDialog() == true)
            {
                using (StreamReader reader = new StreamReader(openFileDialog.FileName))
                {
                    while (!reader.EndOfStream)
                    {
                        try
                        {
                            usersList.Add(parser.Parse(reader.ReadLine()));
                        }
                        catch (FormatException)
                        {
                            MessageBox.Show($"Failed to parse content in file, {openFileDialog.FileName}");
                        }
                        catch (IndexOutOfRangeException)
                        {
                            MessageBox.Show($"Failed to parse content in file, {openFileDialog.FileName}");
                        }
                        catch (Exception)
                        {
                            MessageBox.Show($"Could not open file, {openFileDialog.FileName}");
                        }
                    }
                }
                statusBar.NumberOfElements = usersList.Count;
            }
        }
        /// <summary>
        /// Deletes a user associated to the organization.
        /// </summary>
        /// <param name="user_id">The user_id is the identifier of the user.</param>
        /// <returns>System.String.<br></br>The success message is "The user has been removed from your organization."</returns>
        public string Delete(string user_id)
        {
            string url      = baseAddress + "/" + user_id;
            var    response = ZohoHttpClient.delete(url, getQueryParameters());

            return(UserParser.getMessage(response));
        }
 private UserDAOImplementation()
 {
     Logging.singlton(nameof(UserDAO));
     driver = DatabaseDriverImplementation.getInstance();
     parser = UserParserImplementation.getInstance();
     driver.createTable(DatabaseConstants.CREATE_USER_TABLE);
 }
Example #7
0
        public async Task <ActionResult> UserProfile(UserProfileViewModel model)
        {
            var user = UserParser.UserProfileViewModelToUser(model);

            if (!string.IsNullOrEmpty(model.Password))
            {
                if ((string.IsNullOrEmpty(model.NewPassword) | string.IsNullOrEmpty(model.ConfirmNewPassword)) || !ModelState.IsValid)
                {
                    return(Json(new
                    {
                        success = false,
                        errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                 .Select(m => m.ErrorMessage).ToArray()
                    }));
                }

                user.Password    = model.Password;
                user.NewPassword = model.NewPassword;
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new
                    {
                        success = false,
                        errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                 .Select(m => m.ErrorMessage).ToArray()
                    }));
                }
            }

            var response = await _userManager.Update(user, (ClaimsIdentity)this.User.Identity);

            if (response.IsSuccess)
            {
                CultureSetter.Set(model.Culture, this);

                return(Json(new
                {
                    success = true
                }));
            }

            if (response.Message.Equals("Wrong current password", StringComparison.OrdinalIgnoreCase))
            {
                return(Json(new
                {
                    success = false,
                    errors = new string[] { ProjectResources.ResourceErrors.ChangePasswordError }
                }));
            }

            return(Json(new
            {
                success = false,
                errors = new string[] { response.Message }
            }));
        }
Example #8
0
        public void UserProfileParser_Parse()
        {
            string testHtml = FileIO.ReadToEnd("samples/profiles_html.txt");

            var parser   = new UserParser <UserProfile>();
            var profiles = parser.Parse(testHtml);

            Assert.NotNull(profiles);
            Assert.NotEmpty(profiles);
        }
Example #9
0
        public async Task <User> GetUser(string userName)
        {
            User       result     = null;
            UserParser parser     = new UserParser();
            var        htmlSource = await NetworkHelper.GetHtmlPageSource("https://pikabu.ru/@" + userName);

            if (htmlSource != null)
            {
                result = await parser.ParseAsync(htmlSource);
            }
            return(result);
        }
Example #10
0
        private IEnumerable <User> getFriendsOnlineIds()
        {
            IEnumerable <User> userListWithId = new List <User>();

            parameters.Clear();
            parameters["method"] = "friends.getOnline";
            XmlDocument resp   = api.RunRequest(parameters);
            UserParser  parser = new UserParser();

            parser.SetResponse(resp);
            userListWithId = parser.ParseResponse() as IEnumerable <User>;
            return(userListWithId);
        }
Example #11
0
        public async Task <ActionResult> Registration(RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    success = false,
                    errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                             .Select(m => m.ErrorMessage).ToArray()
                }));
            }

            var user     = UserParser.RegistrationViewModelToUser(model);
            var response = await _userManager.CreateIdentity(user);

            if (response.IsSuccess)
            {
                _authManager.SignIn((ClaimsIdentity)response.Object);
                CultureSetter.Set(model.Culture, this);

                return(Json(new
                {
                    success = true
                }));
            }

            string error = string.Empty;

            if (response.Message.Equals("Username is already taken", StringComparison.OrdinalIgnoreCase))
            {
                error = ProjectResources.ResourceErrors.UserNameIsTaken;
            }

            if (response.Message.Equals("Email is already taken", StringComparison.OrdinalIgnoreCase))
            {
                error = ProjectResources.ResourceErrors.EmailIsTaken;
            }


            return(Json(new
            {
                success = false,
                errors = new string[] { error }
            }));
        }
Example #12
0
        static void Main(string[] args)
        {
            PlaybookConsructor   consructor     = new PlaybookConsructor();
            PlaybookWriter       writer         = new PlaybookWriter();
            TeachersWriter       teachersWriter = new TeachersWriter();
            UserParser <Teacher> teacherParser  = new UserParser <Teacher>();
            UserParser <Student> studentParser  = new UserParser <Student>();
            string studentsAPI = "https://smiap.ru/api/v1/students/";
            string teachersAPI = "https://smiap.ru/api/v1/teachers/";

            List <Student> students = studentParser.ParseUserList(studentsAPI);
            List <Teacher> teachers = teacherParser.ParseUserList(teachersAPI);

            var yaml = consructor.SerializeToYaml(students);

            writer.WritePalybook(students, yaml);
            teachersWriter.WriteTeachersList(teachers);
            Console.Write(yaml);
        }
Example #13
0
        public async Task <IActionResult> GetUserList()
        {
            try
            {
                var users = await this._userService.GetList();

                var result = users.Select(x => UserParser.UserDtoToUserModel(x)).ToList();

                return(Ok(new
                {
                    Users = result
                }));
            }
            catch (UserException exception)
            {
                return(BadRequest(new { exception.Message }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Example #14
0
        public async Task TestParseUser(string teststr, string username, uint uid, string regdate, string title, bool zero, bool isBanned)
        {
            var usersearch = new SearchPageParser(new NetcupSearchInfo());
            var parser     = new UserParser(new NetcupUserInfo());

            var users = new ForumUserCollection(parser);

            foreach (var newUser in await usersearch.SearchUserAsync(username))
            {
                await users.ImportAsync(newUser);
            }

            var user = users.Get(username);

            Assert.Equal <uint>(uid, user.Uid);
            Assert.Equal(teststr, user.Url);
            Assert.Equal(username, user.Username);
            Assert.Equal(DateTime.ParseExact(regdate, "yyyy-MM-dd", CultureInfo.InvariantCulture), user.MemberSince);
            Assert.Equal(title, user.Title);
            Assert.True(zero ? user.PostCount == 0 : user.PostCount > 0);
            Assert.Equal(isBanned, user.IsBanned);
        }
Example #15
0
        public async Task <IActionResult> Get(int id)
        {
            if (id <= 0)
            {
                return(BadRequest(new { Message = "Invalid client request" }));
            }

            try
            {
                var user = await this._userService.FindById(id);

                if (user is null)
                {
                    return(NotFound(new { Message = "User not found" }));
                }

                var roles = await this._userService.GetRoles(user.UserName);

                var links = HypermediaHelper.GetUserHypermediaLinks(this, id);

                var userResult = UserParser.UserDtoToUserModel(user);
                userResult.Roles = roles.ToList();

                return(Ok(new
                {
                    User = userResult,
                    Links = links
                }));
            }
            catch (UserException exception)
            {
                return(BadRequest(new { exception.Message }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Example #16
0
        public async Task <IActionResult> Post([FromBody] CreateUpdateUserModel model)
        {
            if (model is null)
            {
                return(BadRequest(new { Message = "Invalid client request" }));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Message = ModelState.Values.SelectMany(x => x.Errors) }));
            }

            try
            {
                var user = UserParser.CreateUpdateUserModelToUserDto(model);

                await _userService.Create(user);
                await UpdateRoles(user, model.Roles);

                var links = HypermediaHelper.PostUserHypermediaLinks(this, user.Id);

                return(Ok(new
                {
                    Message = "User was created",
                    Links = links
                }));
            }
            catch (UserException exception)
            {
                return(BadRequest(new { exception.Message }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        public static CompaniesUsersAddresses LoadFrom(ITableReader reader)
        {
            Company[] companies = null;
            User[] users = null;
            Address[] addresses = null;

            foreach (ITable table in reader.GetTables())
            {
                switch (table.Name)
                {
                    case "Companies":
                        companies = new CompanyParser().GetAll(table).ToArray();
                        break;
                    case "Users":
                        users = new UserParser().GetAll(table).ToArray();
                        break;
                    case "Addresses":
                        addresses = new AddressParser().GetAll(table).ToArray();
                        break;
                }
            }

            return new CompaniesUsersAddresses(companies, users, addresses);
        }
Example #18
0
        public async Task <IActionResult> Register([FromBody] CreateUserModel model)
        {
            if (model is null)
            {
                return(BadRequest(new { Message = "Invalid client request" }));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Message = ModelState.Values.SelectMany(x => x.Errors) }));
            }

            try
            {
                var user = UserParser.CreateUserModelToUserDto(model);

                await _userService.Create(user);

                var token = await this._userManager.GenerateToken(user);

                await _userService.SetRefreshToken(user.Id, token.RefreshToken);

                //add hypermedia
                var links = HypermediaHelper.AuthHypermediaLinks(this);

                return(Ok(new { token, links }));
            }
            catch (UserException exception)
            {
                return(BadRequest(new { exception.Message }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Example #19
0
 internal override void ParseAnswer()
 {
     parser = new UserParser();
     parser.SetResponse(response);
     vkObject = parser.ParseResponse();
 }
Example #20
0
        private static void MessageHandler(NetworkStream stream)
        {
            string[] data;
            Account  newUser = new Account();

            data = Recieve(stream);

            if (data[0] == "reg")
            {
                newUser.username = data[1];
                newUser.password = data[2];

                Account.registeredAccounts.Add(newUser);

                StreamWriter writer = File.AppendText("users.txt");
                writer.WriteLine(data[1] + "\\" + data[2]);

                writer.Close();
                Console.WriteLine("[" + DateTime.Today + "] " + data[1] + " has registered!");
            }
            else if (data[0] == "administration")
            {
                newUser.username = "******";
                newUser.password = "******";

                if (!Account.CheckAcc(newUser, data[0], data[1]))
                {
                    SendData(stream, "False\\Incorrect admin password");
                    return;
                }

                switch (data[2])
                {
                case "ping":
                    SendData(stream, "True");
                    break;

                case "getreg":
                    StringBuilder builder = new StringBuilder();
                    foreach (var regUser in File.ReadAllLines("users.txt"))
                    {
                        builder.Append("\\" + regUser);
                    }

                    SendData(stream, "True" + builder.ToString());
                    break;

                case "remusr":
                    string[] users = UserParser.GetUsers();

                    foreach (var user in  users)
                    {
                        string[] splitted = UserParser.ParseUserInfo(user);

                        if (splitted[0] == data[3])
                        {
                            List <string> temp = users.ToList();

                            temp.Remove(user);

                            File.WriteAllLines("users.txt", temp.ToArray());

                            SendData(stream, "True");
                        }
                    }
                    break;

                case "addusr":
                    StreamWriter writer = File.AppendText("users.txt");
                    writer.WriteLine(data[3] + "\\" + data[4]);
                    writer.Close();

                    SendData(stream, "True");
                    break;

                case "getusr":
                    if (!UserParser.Exists(data[3]))
                    {
                        SendData(stream, "User does not exist");
                        return;
                    }

                    string userInfo = UserParser.FindUser(data[3]);

                    SendData(stream, "True\\" + userInfo);
                    break;

                default:
                    SendData(stream, "False\\Command does not exist");
                    break;
                }

                return;
            }
            else
            {
                string errorCode = "Incorrect username or password";
                bool   result    = false;

                foreach (var registered in Account.registeredAccounts)
                {
                    if (Account.CheckAcc(registered, data[1], data[2]))
                    {
                        if (onlineUsers.Exists(on => on.username == registered.username))
                        {
                            errorCode = "User is already logged in";
                            break;
                        }
                        SendData(stream, "True");

                        newUser.username = data[1];
                        newUser.password = data[2];
                        newUser.stream   = stream;

                        onlineUsers.Add(newUser);

                        result = true;
                        Console.WriteLine("[" + DateTime.Today + "] " + data[1] + " has connected");
                        SendServerMsg($"{newUser.username} has connected");

                        break;
                    }
                }

                if (!result)
                {
                    SendData(stream, "False\\" + errorCode);
                    return;
                }

                while (true)
                {
                    data = Recieve(stream);

                    switch (data[0])
                    {
                    case "msg":
                        if (!Account.CheckAcc(newUser, data[1], data[2]))
                        {
                            return;
                        }

                        MsgInfo info = new MsgInfo();

                        info.user    = newUser;
                        info.message = data[3];
                        Console.WriteLine("[" + DateTime.Today + "] " + info.user + ": " + info.message);
                        msgQueue.Add(info);
                        break;

                    case "exit":
                        if (!Account.CheckAcc(newUser, data[1], data[2]))
                        {
                            return;
                        }

                        foreach (var user in onlineUsers)
                        {
                            if (user.username == data[1])
                            {
                                onlineUsers.Remove(user);
                                Console.WriteLine("[" + DateTime.Today + "] " + data[1] + " has disconnected");
                                SendServerMsg($"{user.username} has disconnected");
                            }
                        }

                        break;
                    }
                }
            }
        }