コード例 #1
0
        private async void createAccount_Click(object sender, EventArgs e)
        {
            RegisterBindingModel newUser = new RegisterBindingModel();
            newUser.Email = this.textBoxEmail.Text;
            newUser.Password = this.textBoxPassword.Text;
            newUser.ConfirmPassword = this.textBoxConfirmPassword.Text;

            using (var client = new HttpClient())
            {
                var serializedProduct = JsonConvert.SerializeObject(newUser);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PostAsync(this.URI_CREATE_ACCOUNT, content);
                if ((int)result.StatusCode == 200)
                {
                    MessageBox.Show(string.Format("{0} was created.", newUser.Email), "Registration");
                    this.textBoxEmail.Clear();
                    this.textBoxPassword.Clear();
                    this.textBoxConfirmPassword.Clear();
                }
                else
                {
                    MessageBox.Show(string.Format("Error while creating{0}! Details: {1}", newUser.Email, result.ReasonPhrase));
                }
            }
        }
コード例 #2
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: Hardik21/JobsABA
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IdentityUser user = new IdentityUser
            {
                UserName = model.UserName
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);
            IHttpActionResult errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }

            return Ok();
        }
コード例 #4
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (string.IsNullOrEmpty(model.RoleName))
                model.RoleName = "Usuário";

            var user = new ApplicationUser()
            {
                UserName = model.Email,
                Email = model.Email,
                FirstName = model.FirstName,
                LastName = model.LastName,
                PhoneNumber = model.PhoneNumber,
                WorkNumber = model.WorkNumber,
                EmailConfirmed = true
            };
            var result = await _repository.UserManager.CreateAsync(user, model.Password);
            if (!result.Succeeded)
                return GetErrorResult(result);

            if (!_repository.RoleManager.RoleExists(model.RoleName))
                _repository.RoleManager.Create(new IdentityRole(model.RoleName));

                var role = _repository.RoleManager.FindByName(model.RoleName);
                var roleResult = _repository.UserManager.AddToRole(user.Id, role.Name);

            return !roleResult.Succeeded ? GetErrorResult(roleResult) : Ok(user);
        }