Esempio n. 1
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            await SetInitialDataAsync();

            if (ModelState.IsValid)
            {
                UserDTO userDto = _mapper.Map <UserDTO>(model);
                userDto.ProfilePhoto = await GetDefaultProfileImage();

                OperationDetails operationDetails = await _userManagementService.Create(userDto);

                if (operationDetails.Succeeded)
                {
                    return(RedirectToAction("SendEmailConfirmation", "Email", new {
                        area = "User",
                        userName = userDto.UserName
                    }));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }

            return(View(model));
        }
Esempio n. 2
0
        public IHttpActionResult RegisterUser([FromBody] UserViewModel userViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = _userManagementService.IsUsernameAvailable(userViewModel.UserName);

            if (!user)
            {
                var response1 = Request.CreateResponse(HttpStatusCode.Forbidden, "Username not available");

                return(ResponseMessage(response1));
            }

            var userDto = UserViewModelAdapter.BuildUserDto(userViewModel);

            _userManagementService.Create(userViewModel.SubscriberEmail, userDto);

            var userSub = _userManagementService.GetUserByEmail(userViewModel.SubscriberEmail);

            var id = _signalRCache.GetConnectionId(userSub.Id);

            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            var notification = new NotificationDto()
            {
                Text   = $"User {userDto.UserName} requested access to your albums",
                UserId = userSub.Id
            };

            _notificationSerice.Save(notification);

            var ctx = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            ctx.Clients.Client(id).albumRequest(notification.Text);

            var response = Request.CreateResponse(HttpStatusCode.Created, userViewModel);

            return(ResponseMessage(response));
        }
Esempio n. 3
0
        public async Task <object> Register([FromBody] UserCredentialsModel model)
        {
            var result = await _userManagementService.Create(model);

            if (result.Succeeded)
            {
                return(_resultManagementService.Result("User registration success.", "200"));
            }

            return(_resultManagementService.Result("User registration failed.", "400"));
        }
Esempio n. 4
0
        public async Task <Account> Create(AccountCreationData data)
        {
            var account = _mapper.Map <Account>(data);

            // TODO: currently set default organization
            account.OrganizationId = new Guid("D9A36195-6571-47A8-89EB-912E02C5512B");
            CommonResult result = await _userManagementService.Create(account, data.Password);

            if (!result.Succeeded)
            {
                throw new Exception(string.Join(", ", result.Errors));
            }

            return(account);
        }
        public async Task <ActionResult> Registrar(UserRegisterViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            var result = await _userManagementService.Create(viewModel).ConfigureAwait(true);

            if (!result.Succeeded)
            {
                return(BadRequest(result.ToString()));
            }

            viewModel.Senha         = string.Empty;
            viewModel.ConfirmaSenha = string.Empty;

            return(Ok(viewModel));
        }
        public ActionResult AddStudentRol(AccountbeheerVM model)
        {
            bool inArray = false;
            List <StudentRollen> studentrollen = new List <StudentRollen>();

            for (int i = 0; i < model.SelectedRolId.Count; i++)
            {
                Rol selectedRol = new Rol();
                for (int s = 0; s < studentrollen.Count; s++)
                {
                    if (model.SelectedStudentId[i].Equals(studentrollen[s].Student.ID))
                    {
                        for (int r = 0; r < studentrollen[s].Rollen.Count; r++)
                        {
                            //unieke studentrol?
                            if (model.SelectedRolId[i].Equals(studentrollen[s].Rollen[r].ID))
                            {
                                ViewBag.Error = "De rol voor een gekozen student dient uniek te zijn.";

                                var accountbeheerVM = new AccountbeheerVM();

                                accountbeheerVM.Studenten = new SelectList(studentService.GetStudenten(), "ID", "Naam");
                                accountbeheerVM.Accounts  = studentService.GetUsers();

                                accountbeheerVM.Rollen = new SelectList(studentService.GetRoles(), "ID", "Naam");

                                List <StudentKeuzeVM> studentKeuzes = new List <StudentKeuzeVM>();

                                foreach (ApplicationUser beoordelaar in accountbeheerVM.Accounts)
                                {
                                    StudentKeuzeVM vm = new StudentKeuzeVM();

                                    vm.Studenten        = studentService.GetStudentenByStudentRollen(beoordelaar.StudentRollen);
                                    vm.RollenPerStudent = studentService.GetRollenByStudent(beoordelaar.StudentRollen);
                                    vm.Aantal           = studentService.GetAantalTeTonenStudenten(beoordelaar.StudentRollen);
                                    vm.StudentenString  = studentService.SerializeObject(vm.Studenten, vm.RollenPerStudent, beoordelaar.Id);

                                    studentKeuzes.Add(vm);
                                }

                                accountbeheerVM.studentKeuzesVM = studentKeuzes;
                                accountbeheerVM.StudentenString = studentService.SerializeObject(accountbeheerVM.Accounts);

                                accountbeheerVM.SelectedStudentId = model.SelectedStudentId;
                                accountbeheerVM.SelectedRolId     = model.SelectedRolId;

                                return(View(accountbeheerVM));
                            }
                        }
                        selectedRol = studentService.GetRolById(model.SelectedRolId[i]);
                        studentrollen[s].Rollen.Add(selectedRol);
                        inArray = true;
                    }
                }
                if (!inArray)
                {
                    Student    selectedStudent = studentService.GetStudentByID(model.SelectedStudentId[i]);
                    List <Rol> selectedRollen  = new List <Rol>();
                    selectedRollen.Add(studentService.GetRolById(model.SelectedRolId[i]));
                    StudentRollen studentrol = studentrolService.CreateStudentrol(selectedStudent, selectedRollen);
                    studentrollen.Add(studentrol);
                }
            }

            var user = new ApplicationUser()
            {
                UserName = model.registerVM.UserName
            };

            user.StudentRollen = studentrollen;

            var users = studentService.GetUsers();

            foreach (ApplicationUser gebruiker in users)
            {
                //unieke gebruiker?
                if (gebruiker.UserName.ToLower() == user.UserName.ToLower())
                {
                    ViewBag.Error = "De gebruiker bestaat al.";

                    var accountbeheerVM = new AccountbeheerVM();

                    accountbeheerVM.Studenten = new SelectList(studentService.GetStudenten(), "ID", "Naam");
                    accountbeheerVM.Accounts  = studentService.GetUsers();

                    accountbeheerVM.Rollen = new SelectList(studentService.GetRoles(), "ID", "Naam");

                    List <StudentKeuzeVM> studentKeuzes = new List <StudentKeuzeVM>();

                    foreach (ApplicationUser beoordelaar in accountbeheerVM.Accounts)
                    {
                        StudentKeuzeVM vm = new StudentKeuzeVM();

                        vm.Studenten        = studentService.GetStudentenByStudentRollen(beoordelaar.StudentRollen);
                        vm.RollenPerStudent = studentService.GetRollenByStudent(beoordelaar.StudentRollen);
                        vm.Aantal           = studentService.GetAantalTeTonenStudenten(beoordelaar.StudentRollen);
                        vm.StudentenString  = studentService.SerializeObject(vm.Studenten, vm.RollenPerStudent, beoordelaar.Id);

                        studentKeuzes.Add(vm);
                    }

                    accountbeheerVM.studentKeuzesVM = studentKeuzes;
                    accountbeheerVM.StudentenString = studentService.SerializeObject(accountbeheerVM.Accounts);

                    accountbeheerVM.SelectedStudentId = model.SelectedStudentId;
                    accountbeheerVM.SelectedRolId     = model.SelectedRolId;

                    return(View(accountbeheerVM));
                }
            }
            var result = userService.Create(user, model.registerVM.Password);

            userService.AddUserToRoleUser(user.Id);
            return(RedirectToAction("AddStudentRol", "Accountbeheer"));
        }