Пример #1
0
        public async Task <IActionResult> Register(
            [FromBody] RegisterDto model)
        {
            var user   = model.GetUser();
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action("confirmEmail", "Account",
                                             new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme);
                await _emailService.ConfirmAccount(model.Email, callbackUrl !);

                return(Ok());
            }

            return(BadRequest(_localizer["User creation failed."]));
        }
Пример #2
0
        public async Task <int> Create(UserAddRequest data, UserStatus status = UserStatus.Active)
        {
            if (data == null)
            {
                throw new ArgumentNullException("Parameter data is required");
            }
            string storedProc = "[dbo].[Users_InsertV7]";

            int    empId          = 0;
            string password       = data.Password;
            string hashedPassword = BCrypt.Net.BCrypt.HashPassword(password);
            Guid   sqlToken       = Guid.Empty;

            _dataProvider.ExecuteNonQuery(storedProc
                                          , delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@UserName", data.Username);
                paramCollection.AddWithValue("@IsConfirmed", data.IsConfirmed = false);
                paramCollection.AddWithValue("@EmailAddress", data.EmailAddress);
                paramCollection.AddWithValue("@Password", hashedPassword);
                paramCollection.AddWithValue("@StatusId", (int)status);

                SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                idParameter.Direction    = System.Data.ParameterDirection.Output;

                SqlParameter token = new SqlParameter("@Token", System.Data.SqlDbType.UniqueIdentifier);
                token.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(idParameter);
                paramCollection.Add(token);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                Int32.TryParse(param["@Id"].Value.ToString(), out empId);
                Guid.TryParse(param["@Token"].Value.ToString(), out sqlToken);
            });

            bool isSuccessful = await _emailService.ConfirmAccount(data.EmailAddress, sqlToken);

            return(empId);
        }