コード例 #1
0
 public HttpResponseMessage Post([FromBody] UserModel newUser)
 {
     try
     {
         if (ModelState.IsValid)
         {
             UserModel addedUser = usersManager.AddUser(newUser);
             if (addedUser != null)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, true));
             }
         }
         else
         {
             var errorMessage = ModelState.Values.SelectMany(v => v.Errors).ToList().Select(e => e.ErrorMessage).Where(e => e != "").FirstOrDefault();
             if (errorMessage == null)
             {
                 errorMessage = ModelState.Values.SelectMany(v => v.Errors).ToList().Select(e => e.Exception).Where(e => e.Message != "").Select(e => e.Message).FirstOrDefault();
             }
             if (errorMessage != null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
             }
         }
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, new HttpError("Problem in user data")));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new HttpError(ex.Message)));
     }
 }
コード例 #2
0
ファイル: DehaxOS.cs プロジェクト: Dehax/DehaxOS
        /// <summary>
        /// Выполняет инициализацию ядра ОС.
        /// </summary>
        public DehaxOS()
        {
            _fileSystemImage = new FileStream(FS_IMAGE_PATH, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, FS_IMAGE_BUFFER, FileOptions.RandomAccess);
            FileSystem = new DehaxFileSystem(_fileSystemImage, ROOT_USER_ID, ROOT_GROUP_ID);

            Scheduler = new DehaxScheduler();

            _usersManager = new UsersManager();
            _groupsManager = new GroupsManager();

            IsLoggedIn = false;

            if (IsFirstRun)
            {
                User rootUser = new User(ROOT_USER_NAME, ROOT_USER_PASSWORD_HASH, ROOT_USER_ID, ROOT_GROUP_ID);
                _usersManager.AddUser(rootUser);
                Group rootGroup = new Group(ROOT_GROUP_NAME, ROOT_GROUP_ID);
                rootGroup.AddUser(rootUser);
                _groupsManager.AddGroup(rootGroup);

                ROOT_USER = rootUser;
                User = rootUser;
                IsLoggedIn = true;

                Install();

                IsLoggedIn = false;
            }
            else
            {
                Initialize();
            }
        }
コード例 #3
0
 public ActionResult AddUser(RegisterViewModel user, string role)
 {
     logManager.AddEventLog("ManageUsersController(Admin area) => AddUser ActionResult called(POST)", "ActionResult");
     if (ModelState.IsValid)
     {
         var newUser = new ApplicationUser
         {
             UserName        = user.UserName,
             Email           = user.Email,
             Age             = user.Age,
             FirstName       = user.FirstName,
             LastName        = user.LastName,
             UserInformation = user.UserInformation
         };
         usersManager.AddUser(newUser, user.Password, role);
         return(RedirectToAction("DisplayUsers", new { statusMessage = "You succesfully added new user!" }));
     }
     else
     {
         ViewBag.Roles = new List <string> {
             "Admin", "Lector", "Student"
         };
         return(View());
     }
 }
コード例 #4
0
        public async Task <ActionResult> AddReservationAsync([FromBody] ReservationDTO reservation)
        {
            if (reservation.Note == null)
            {
                reservation.Note = "Aucune note";
            }
            if (reservation == null)
            {
                return(new EmptyResult());
            }

            if (reservation.StartDate < DateTime.Now || reservation.StartDate > reservation.EndDate)
            {
                var result = new ObjectResult(reservation)
                {
                    StatusCode = 409
                };
                return(result);
            }
            // call manager to find if id is taken or not
            if (!await _reservationsManager.CheckReservationRange(reservation.RoomID, reservation.StartDate, reservation.EndDate))
            {
                //return StatusCode(409 );
                var result = new ObjectResult(reservation)
                {
                    StatusCode = 409
                };
                return(result);
            }
            else
            {
                var userLdap = _usersManager.GetUsername();

                bool userExist = await _usersManager.VerifyUsername(userLdap);

                if (!userExist)
                {
                    await _usersManager.AddUser(userLdap);
                }

                var user = await _usersManager.GetUserIDAsync(userLdap);

                reservation.UserID = user.UserID;


                reservation.StartDate = reservation.StartDate.AddSeconds(-reservation.StartDate.Second);
                reservation.EndDate   = reservation.EndDate.AddSeconds(-reservation.EndDate.Second);
                // find DTO & Mapping
                var reservationMapped = _mapper.Map <ReservationDTO, Reservation>(reservation);
                //call manager once again to add it this time
                await _reservationsManager.AddReservation(reservationMapped);

                return(Ok());
            }
        }
コード例 #5
0
ファイル: LoginViewModel.cs プロジェクト: yonifra/semjournals
        private void SignUp()
        {
            var userType = IsPublisher ? UserType.Publisher : UserType.User;

            var result = AuthenticationManager.Instance.AddUser(Username, Password);

            if (result)
            {
                UsersManager.AddUser(Username, userType);
            }

            MessageBox.Show(result ? "Signed up!" : "Error signing up");
        }
コード例 #6
0
        private void AddNewUser()
        {
            if (IsNewUser)
            {
                manager.AddUser(User);
            }
            else
            {
                manager.UpdateUser(_oldUser, User);
            }

            if (Close != null)
            {
                Close();
            }
        }
コード例 #7
0
        private void OnAddUserCommandExecuted(object parameter)
        {
            var newUser = new User()
            {
                Name      = "Имя",
                Login     = "******",
                Password  = "******",
                CompanyId = selectedCompany.Id
            };

            UsersManager.AddUser(newUser);
            Users.Add(newUser);
            selectedUser = newUser;

            OnPropertyChanged(nameof(SelectedUser));
        }
コード例 #8
0
ファイル: addUser.aspx.cs プロジェクト: IstatCooperation/SDGs
    protected void AddUser(object sender, EventArgs e)
    {
        UsersManager um = new UsersManager();

        try
        {
            um.AddUser(txtUser.Value, txtUserPass.Value, ddlRoles.Items[ddlRoles.SelectedIndex].Value, ddlRoles.Items[ddlRoles.SelectedIndex].Text);
            //   saveMessage.Text = "<div class='db-alert db-success hideMe'>Data updated successfully</div>";
            Response.Redirect("~/Users/usersList.aspx?msg=true");
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Exception caught. " + ex.Message);
            saveMessage.Text = "<div class='db-alert db-error hideMe'>Warning! Data not updated</div>";
        }
    }
コード例 #9
0
        internal static void CreateUser()
        {
            Console.WriteLine("Input user name:");
            var name = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(name))
            {
                Console.WriteLine("The Name cannot be empty");
            }

            Console.WriteLine("Input user BirthDay in format dd.MM.yyyy:");
            DateTime birthday; // = DateTime.Parse(Console.ReadLine());

            string[] input_date;

            try
            {
                input_date = Console.ReadLine().Split(new[] { '.' }, 3);
                birthday   = new DateTime(int.Parse(input_date[2]), int.Parse(input_date[1]), int.Parse(input_date[0]));
            }
            catch
            {
                Console.WriteLine("Wrong input date of birth.");
                return;
            }

            try
            {
                if (usersmanager.AddUser(name, birthday))
                {
                    Console.WriteLine("User created successfully");
                }
                else
                {
                    Console.WriteLine("User do not created");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("User do not created");
                Console.WriteLine(e);
            }
        }
コード例 #10
0
ファイル: RegisterPage.xaml.cs プロジェクト: jkicmal/passtore
        private async void RegisterButton_Clicked(object sender, EventArgs e)
        {
            string login = loginEntry.Text;
            string pass1 = passEntry.Text;
            string pass2 = passRepeatEntry.Text;

            bool flag = true;

            if (!ValidationUtils.IsUsername(login))
            {
                flag = false;
                await DisplayAlert("Błąd", "Niepoprawna nazwa użytkownika", "Rozumiem");
            }
            if (pass1.Length < 8)
            {
                flag = false;
                await DisplayAlert("Błąd", "Hasło powinno mieć przynajmniej 8 znaków", "Rozumiem");
            }
            if (pass1 != pass2)
            {
                flag = false;
                await DisplayAlert("Błąd", "Hasła nie pasują do siebie", "Rozumiem");
            }

            User user = new User(login);

            if (UsersManager.CheckIfAlreadyInDB(user))
            {
                flag = false;
                await DisplayAlert("Błąd", "Podany login jest zajęty", "Rozumiem");
            }

            if (flag)
            {
                await UsersManager.AddUser(user, pass1);
                await DisplayAlert("Sukces!", "Pomyślnie zarejestrowano", "OK");

                await Navigation.PopAsync();
            }
        }
コード例 #11
0
        public void SerialDeserialTest()
        {
            UsersManager mnger = new UsersManager();

            var newUser = new User("admin", "admin");

            newUser.Roles.Add("admin");
            mnger.AddUser(newUser);

            mnger.Save();

            UsersManager saved = UsersManager.LoadUsers();


            foreach (var user in saved.Users)
            {
                Trace.Write(string.Format("name: {0}, pwd: {1}", user.Name, user.Password));
            }


            Assert.IsNotNull(saved["admin"]);
            Assert.IsNull(saved["abc"]);
        }
コード例 #12
0
 // Add
 private void addNewUser_Click(object sender, RoutedEventArgs e)
 {
     // creating
     CreateUser();
     if (!_feedback.IsWorking || !AddTelNumber())
     {
         errorNewUser.Text = _feedback.Message;
     }
     // add to list
     else
     {
         _feedback = _users.AddUser(_feedback.Data);
         if (!_feedback.IsWorking)
         {
             errorNewUser.Text = _feedback.Message;
         }
         // refresh page
         else
         {
             ((Frame)Window.Current.Content).Navigate(typeof(AddUser));
         }
     }
 }
コード例 #13
0
 public void AddUser([FromBody] users1 u1)
 {
     UsersManager.AddUser(u1);
 }
コード例 #14
0
        public ActionResult <int> Post(User user)
        {
            var mgr = new UsersManager();

            return(mgr.AddUser(user));
        }
コード例 #15
0
 // POST: api/student
 public void PostUser(User user)
 {
     um.AddUser(user);
 }
コード例 #16
0
 public void AddUser(string username, UserType type)
 {
     UsersManager.AddUser(username, type);
 }
コード例 #17
0
        static void Run()
        {
            for (; ;)
            {
                Console.WriteLine("-----------------------------------"
                                  + Environment.NewLine + "Please choose option:"
                                  + Environment.NewLine + "\t 1: Add user"
                                  + Environment.NewLine + "\t 2: Delete user"
                                  + Environment.NewLine + "\t 3: See all users"
                                  + Environment.NewLine + "\t 4: Add award"
                                  + Environment.NewLine + "\t 5: Add award to user"
                                  + Environment.NewLine + "\t 6: Delete award"
                                  + Environment.NewLine + "\t 7: See all awards"
                                  + Environment.NewLine + "-----------------------------------");

                if (uint.TryParse(Console.ReadLine(), out uint option) &&
                    option > 0 &&
                    option < 8)
                {
                    UsersManager  manager = new UsersManager();
                    AwardsManager Manager = new AwardsManager();
                    Guid          UserId;
                    Guid          AwardId;
                    switch (option)
                    {
                    case 1:
                    {
                        Console.WriteLine("Enter user name");
                        var Name = Console.ReadLine();

                        Console.WriteLine("Enter date of birth");
                        DateTime DateOfBirth;

                        if (!DateTime.TryParse(Console.ReadLine(), out DateOfBirth))
                        {
                            Console.WriteLine("Error!!! Wrong date format");
                        }
                        else if (DateOfBirth > DateTime.Now)
                        {
                            Console.WriteLine("Error!!! Wrong date");
                        }
                        else
                        {
                            Userss newUser = new Userss(Name, DateOfBirth);

                            manager.AddUser(newUser);
                        }

                        break;
                    }

                    case 2:
                    {
                        Console.WriteLine("Enter user id");

                        if (!Guid.TryParse(Console.ReadLine(), out UserId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId))
                        {
                            Console.WriteLine("Error!!! This user does not exist");
                        }
                        else
                        {
                            manager.DeleteUser(UserId);
                        }


                        break;
                    }

                    case 3:
                    {
                        foreach (Userss user in manager.GetAllUsers())
                        {
                            Console.WriteLine(user);
                        }

                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("Enter award name");
                        var Name = Console.ReadLine();

                        Awards award = new Awards(Name);
                        Manager.AddAward(award);

                        break;
                    }

                    case 5:
                    {
                        Console.WriteLine("Enter user Id");

                        if (!Guid.TryParse(Console.ReadLine(), out UserId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!manager.GetAllUsers().Exists(n => n.UserId == UserId))
                        {
                            Console.WriteLine("Error!!! This user does not exist");
                        }
                        else
                        {
                            Console.WriteLine("Enter award Id");

                            if (!Guid.TryParse(Console.ReadLine(), out AwardId))
                            {
                                Console.WriteLine("Error!!! Wrong id format");
                            }
                            else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId))
                            {
                                Console.WriteLine("Error!!! This award does not exist");
                            }
                            else
                            {
                                manager.AddAwardToUser(UserId, AwardId);
                            }
                        }

                        break;
                    }

                    case 6:
                    {
                        Console.WriteLine("Enter award Id");

                        if (!Guid.TryParse(Console.ReadLine(), out AwardId))
                        {
                            Console.WriteLine("Error!!! Wrong id format");
                        }
                        else if (!Manager.GetAllAwards().Exists(n => n.Id == AwardId))
                        {
                            Console.WriteLine("Error!!! This award does not exist");
                        }
                        else
                        {
                            Manager.DeleteAward(AwardId);
                        }

                        break;
                    }

                    case 7:
                    {
                        foreach (Awards award in Manager.GetAllAwards())
                        {
                            Console.WriteLine(award);
                        }

                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Unknown command!");
                        break;
                    }
                    }
                }
                else
                {
                    Console.WriteLine("Error!!! Wrong option");
                }
            }
        }