Exemplo n.º 1
0
        public async Task<IHttpActionResult> AddUser([FromBody] RegisterModel model)
        {
            var user = new ApplicationUser();
            user.ApplyChanges(model);

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                return Ok("Registered");
            }

            return new BadRequestResult(new HttpRequestMessage(HttpMethod.Post, result.Errors.ToString()));
        }
Exemplo n.º 2
0
        public void RegisterModelFactory(ApplicationUser user)
        {
            var myType = GetType();
            var props = new List<PropertyInfo>(myType.GetProperties());
            foreach (var prop in props)
            {
                if ((prop.Name.ToLower() == "password") || (prop.Name.ToLower() == "confirmpassword"))
                    continue;

                var pi = typeof(ApplicationUser).GetProperty(prop.Name);
                var piD = typeof (RegisterModel).GetProperty(prop.Name);

                if ((pi == null) || (piD== null))
                    continue;

                var val = pi.GetValue(user);
                
                if (val != null)
                    piD.SetValue(this, val);
            }

        }
        public async Task<IHttpActionResult> Register(RegisterModel model)
        {
            var user = new ApplicationUser();
            user.ApplyChanges(model);

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                return Ok("Registered");
            }

            var errors = result.Errors.Aggregate("", (current, error) => $"{current}\r\n{error}");

            return BadRequest(errors);
        }
        public async Task<IHttpActionResult> UpdateRegistrationWithExternalProvider([FromBody] RegisterModel model)
        {
            var externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);
            var username = model.UserName;
            var email = model.Email;
            var user = new ApplicationUser
            {
                UserName = username,
                Email = email,
                ImageUrl = model.ImageUrl
            };
            user.Logins.Add(new UserLoginInfo(externalLogin.LoginProvider, externalLogin.ProviderKey));

            var result = await _userManager.CreateAsync(user, "2c517F10-C697-4763-A814-83DFB9FEFE0A"); // TODO: Validate this password when getting new token
            
            var errorResult = GetErrorResult(result);
            if (errorResult != null)
            {
                return errorResult;
            }
            return Ok("Registered");
        }
        public async Task<IHttpActionResult> UpdateRegistrationWithPreregistion([FromBody] RegisterModel model)
        {
            

        var user = new ApplicationUser
            {
                UserName = model.UserName,
                Email = model.Email,
                ImageUrl = model.ImageUrl
            };

            var result = await _userManager.CreateAsync(user, model.Password);
            var errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }
            
            return Ok("Registered.");
        }
 public void DeleteUser(ApplicationUser user)
 {
     UserManager.Delete(user);
 }