public void Should_add()
        {
            initEmpty();
            User user0 = new User(new UserId("0"), "Name0", "FirstName0", new AuthenticateId("0"));

            Assert.IsTrue(userData.Add(user0));
        }
Пример #2
0
 public bool SignUp([FromBody] User user)
 {
     if (user == null)
     {
         return(false);
     }
     else
     {
         user.permision = Roles.USER_ROLE;
         return(source.Add(user));
     }
 }
        public async Task <IHttpActionResult> Post(UserModel model)
        {
            try
            {
                ValidateModel(model);
                if (ModelState.IsValid)
                {
                    var user = mapper.Map <User>(model);
                    db.Add(user);
                    if (!await db.SaveChangesAsync())
                    {
                        return(InternalServerError());
                    }
                    var newModel = mapper.Map <UserModel>(user);
                    return(CreatedAtRoute("GetUser", new { principalName = newModel.PrincipalName }, newModel));
                }

                return(BadRequest(ModelState));
            }
            catch (Exception)
            {
                return(InternalServerError());

                throw;
            }
        }
Пример #4
0
        public ActionResult Create(User_cl user_Cl)
        {
            /*We can access individual html here to check is value and error.
             * var err = ModelState["Username"].Errors;
             * var value = ModelState["Username"].Value;
             */

            /*
             * if (string.IsNullOrEmpty(user_Cl.Username))
             * {
             *  ModelState.AddModelError(nameof(user_Cl.Username), "The username is required");
             * }*/

            if (ModelState.IsValid)
            {
                db.Add(user_Cl);


                //Why we should redirect to some other get request page as after any post if user refresh , second post req will be generate.
                //return View("Details");
                return(RedirectToAction("Details", new { id = user_Cl.UserID }));
            }

            return(View());
        }
Пример #5
0
        public User createADemoUser()
        {
            UserMetaDataModel model = new UserMetaDataModel {
                FirstName          = "Hellen",
                LastName           = "Brown",
                Dob                = DateTime.Now,
                StreetAddressLine1 = "10811 AshtonAve",
                StreetAddressLine2 = "",
                State              = "CA",
                ZipCode            = "90424",
                Income             = BigInteger.Parse("140000"),
                Occupation         = "Engineer"
            };

            UserMetadata userMetadata = new UserMetadata
            {
                Uid = "304-497-354"
            };

            userMetadata.UserMetaDataModel = model;

            User user1 = new User
            {
                Uid = "304-497-354",
            };

            return(userData.Add(user1, userMetadata));
        }
Пример #6
0
        public ApiResult Post([FromBody] User value)
        {
            ApiResult result = new ApiResult();

            try
            {
                User newData = _userData.Add(value);
                if (newData != null)
                {
                    result.IsError = false;
                    result.Message = "Usuario creado con exito";
                    result.data    = newData;
                }
                else
                {
                    result.CodeMsg = 1;
                    result.IsError = true;
                    result.Message = "No se pudo crear el usuario";
                }
            }
            catch (Exception ex)
            {
                result.CodeMsg = 2;
                result.IsError = true;
                result.Message = ex.Message;
            }
            return(result);
        }
Пример #7
0
        public async Task Register(RegisterUserRequestDTO model, string origin)
        {
            var user = _userData.GetByEmail(model.Email);

            if (user != null)
            {
                await SendAlreadyRegisteredEmail(user.Email, origin);

                return;
            }

            var userWithSameUsername = _userData.GetByUsername(model.Username);

            if (userWithSameUsername != null)
            {
                throw new AppException("Username already taken, please use different username.");
            }

            var newUser = _mapper.Map <User>(model);

            //first registered user is an admin
            bool isFirstAccount = _userData.GetCount() == 0;

            if (isFirstAccount)
            {
                newUser.Roles.Add(new Role {
                    RoleKey = RoleKey.admin
                });
            }
            else
            {
                newUser.Roles.Add(new Role {
                    RoleKey = RoleKey.superuser
                });
            }

            newUser.CreatedAt         = DateTime.UtcNow;
            newUser.VerificationToken = JwtToken.randomTokenString();

            newUser.Password = BC.HashPassword(model.Password);

            _userData.Add(newUser);

            await SendVerificationEmail(newUser, origin);
        }
        private void init()
        {
            UserInMemoryAdapter userInMemoryAdapter = new UserInMemoryAdapter();

            userData = new UserInMemoryImpl(userInMemoryAdapter);

            User user1 = new User(new UserId("1"), "Name1", "FirstName1", new AuthenticateId("1"));

            userData.Add(user1);

            User user2 = new User(new UserId("2"), "Name2", "FirstName2", new AuthenticateId("2"));

            userData.Add(user2);

            User user3 = new User(new UserId("3"), "Name3", "FirstName3", new AuthenticateId("3"));

            userData.Add(user3);
        }
Пример #9
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         var u = _UserData.Add(_UserData.ToEntity(MyUser));
         return(RedirectToAction("Details", "Users", new { id = u.Id }));
     }
     return(Page());
 }
Пример #10
0
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     userData.Add(usuario);
     userData.commit();
     return(RedirectToPage("./Usuario"));
 }
Пример #11
0
        public int Register(UserDataObject user)
        {
            RegistrationValidator validator = new RegistrationValidator(userData);

            if (!validator.IsValid(user))
            {
                throw new RegistrationException(validator.ErrorCodes);
            }
            user.EncryptedPassword = IGenProtector.Encrypt(user.Password);
            return(userData.Add(user));
        }
Пример #12
0
        public IActionResult Register([FromBody] Register register)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _userData.Add(register, Request.Headers["origin"]);

            return(CreatedAtAction("GetUser", new { id = register.FirstName }, register));
        }
Пример #13
0
 public ActionResult Create(User user, FormCollection frm)
 {
     if (ModelState.IsValid)
     {
         string mess = db.Add(user);
         if (mess == "")
         {
             return(RedirectToAction("List"));
         }
         else
         {
             ModelState.AddModelError(string.Empty, mess);
         }
     }
     return(View());
 }
Пример #14
0
        public Boolean CreateUser([FromBody] User user)
        {
            /*
             * if (user != null)
             * {
             *  source.Add(user);
             *  return true;
             * }
             * else
             * {
             *  return false;
             * }
             */

            source.Add(user);
            return(true);
        }
Пример #15
0
        public ActionResult CreateUser(User userModel)
        {
            var UserDetails = database.GetUserByName(userModel);

            if (UserDetails == null)
            {
                database.Add(userModel);
                ViewBag.SuccesMessage = "Konto zostało utworzone";

                ModelState.Clear();

                return(RedirectToAction("Index"));
            }

            ViewBag.LoginInUse = "Taki użytkownik jest już zarejstrowany";

            return(View());
        }
Пример #16
0
 public ActionResult Create(UserViewModel user)
 {
     if (user != null)
     {
         user.Initialize(db);
     }
     user.ManagerPrincipalName = db.Get(user.ManagerId)?.PrincipalName;
     ModelState.Clear();
     TryValidateModel(user);
     if (ModelState.IsValid)
     {
         user.Manager = mapper.Map <UserViewModel>(db.Get(user.ManagerId));
         db.Add(mapper.Map <User>(user));
         TempData["Message"] = $"Added user {user.LastName}, {user.FirstName}";
         return(RedirectToAction("Details", new { id = user.Id }));
     }
     return(View(user));
 }
Пример #17
0
        public IActionResult OnPost()
        {
            var user = userData.GetByLogin(User);

            if (user != null)
            {
                userData.SetMessage("Użytkownik o takim loginie istnieje, wybierz inny");
                userData.GetMessage();
                return(RedirectToPage("./CreateUser"));
            }
            else
            {
                userData.Add(User);
                userData.AddBudget();
                userData.Commit();
                userData.SetMessage(string.Empty);
                return(RedirectToPage("./UserCreated"));
            }
        }
        public void AddUser()
        {
            var newuser = new User()
            {
                PrincipalName   = "adduser",
                FirstName       = "New",
                LastName        = "User",
                Email           = "*****@*****.**",
                TelephoneNumber = "3334445555",
                Enabled         = true,
                Title           = "Sales Rep",
                Manager         = null
            };

            db.Add(newuser);
            db.SaveChanges();

            Assert.IsTrue(db.Get(newuser.PrincipalName) != null);
        }
        public IActionResult OnPost(Users UserDetails)
        {
            if (UploadPicture != null)
            {
                UserDetails.ProfilePicture = UploadedProPicture(UploadPicture);
            }

            if (ModelState.IsValid)
            {
                Message = userSignup.Add(UserDetails);
                if (Message == "Added")
                {
                    userSignup.Commit();
                    HttpContext.Session.SetString("username", UserDetails.UserName);
                    return(RedirectToPage("Dashboard", new { urlname = UserDetails.UserName }));
                }
            }
            return(Page());
        }
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (User.Id > 0)
            {
                _data.Update(User);
            }
            else
            {
                _data.Add(User);
            }
            _data.Commit();

            TempData["Message"] = "User saved!";
            return(RedirectToPage("./Detail", new { userId = User.Id }));
        }
        public bool Add(UserDto userDto, string motDePasse)
        {
            if (null != userDto &&
                null != motDePasse &&
                !"".Equals(motDePasse))
            {
                /* On crée les identifiants */
                AuthenticateId authenticateId = authenticateIdGenerator.GenerateId();
                bool           result         = authenticateData.Add(new Authenticate(authenticateId, userDto.Login, userDto.Role), motDePasse);

                if (!result)
                {
                    return(result);
                }

                /* On crée l'utilisateur */
                UserId userId = userIdGenerator.GenerateId();

                return(userData.Add(userDtoAdapter.DtoToModel(userDto, userId, authenticateId)));
            }
            return(false);
        }
 public IActionResult OnPost()
 {
     userData.Add(User);
     // userData.Commit();
     return(RedirectToPage("./List"));
 }
Пример #23
0
 public void Add(User entity)
 {
     _userData.Add(entity);
 }
Пример #24
0
        public IActionResult Add(User newUser)
        {
            _userData.Add(newUser);

            return(Ok());
        }
Пример #25
0
        public IActionResult Register(AddUserDTO user, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                if (_userData.ExistUsername(user.Username, 0))
                {
                    ModelState.AddModelError("Username", "Username taken");
                    return(View(user));
                    //return BadRequest();
                }
                var newUser = new User();
                newUser.Username         = user.Username;
                newUser.FirstName        = user.FirstName;
                newUser.LastName         = user.LastName;
                newUser.Email            = user.Email;
                newUser.Description      = user.Description;
                newUser.Password         = user.Password;
                newUser.Role             = RoleType.User;
                newUser.Blocked          = false;
                newUser.Deleted          = false;
                newUser.RegistrationDate = DateTime.Today;

                if (user.Image != null)
                {
                    newUser.ProfilePictureUrl = AddImage(newUser.Username, user.Image);
                }
                else if (image != null)
                {
                    newUser.ProfilePictureUrl = AddImage(newUser.Username, image);
                }
                else
                {
                    newUser.ProfilePictureUrl = "DefaultUserImage.png";
                }

                newUser = _userData.Add(newUser);

                HttpContext.Session.SetString("LoggedInUserUsername", newUser.Username);
                HttpContext.Session.SetString("LoggedInUserId", newUser.Id.ToString());
                HttpContext.Session.SetString("LoggedInUserRole", newUser.Role.ToString());

                var contentType = Request.ContentType;
                if (contentType != null)
                {
                    if (contentType.Equals("application/json"))
                    {
                        return(Json(newUser));
                    }
                    else if (contentType.Equals("text/html"))
                    {
                        return(RedirectToAction(nameof(HomeController.Home)));
                    }
                    else if (contentType.Equals("application/x-www-form-urlencoded"))
                    {
                        return(RedirectToAction(nameof(HomeController.Home)));
                    }
                    return(RedirectToAction(nameof(GetById), user.Id));
                }
                return(RedirectToAction(nameof(HomeController.Home)));
            }
            else
            {
                return(Json(new UserDTO()));
            }
        }