示例#1
0
        public int CreateUser(User user)
        {
            int result = 0;

            try
            {
                result = _user_object.CreateUser(user);
                if (result > 0)
                {
                    return(result);
                }
                else
                {
                    throw new OASCustomException("Operation failed.");
                }
            }
            catch (SqlException sqlex)
            {
                log.Error(sqlex);
            }
            catch (OASCustomException customex)
            {
                log.Error(customex.Message);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(result);
        }
        public async Task <IActionResult> Register(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "AccountFunctionApi/Register")] HttpRequest req,
            ExecutionContext context)
        {
            var   content = await new StreamReader(req.Body).ReadToEndAsync();
            Users user    = JsonSerializer.Deserialize <Users>(content);

            user.IdRole = 2;
            string responseMessage = String.Empty;
            Users  userDb          = db.CreateUser(user);

            if (userDb != null)
            {
                UserJWT userJwt = new UserJWT()
                {
                    Id       = userDb.Id,
                    Name     = userDb.Name,
                    Surname  = userDb.Surname,
                    Surname2 = userDb.Surname2,
                    Email    = userDb.Email,
                    IdRole   = userDb.IdRole,
                    Rol      = "Client",
                };
                responseMessage = GenerarTokenJWT(userJwt, context);
            }
            else
            {
                responseMessage = String.Empty;
            }
            return(new OkObjectResult(responseMessage));
        }
        public Boolean RegisterProcess(string userNameRegister, string passwordRegister, int age)
        {
            User user = new User
            {
                userName = userNameRegister,
                password = passwordRegister,
                Age      = age
            };

            Boolean Value = UserOperations.CreateUser(user);

            return(Value);
        }
示例#4
0
        } // функция загрузки

        private async void Registration(object sender, RoutedEventArgs e)
        {
            _login = Login.Text;
            string password        = Password.Password;
            string confirmPassword = ConfirmPassword.Password;

            string badgeError = (string)Application.Current.Resources["NotifyErrorBadgeEN"];
            string messagePM  = (string)Application.Current.Resources["NotifyPasswordsMismatchEN"];
            string messageUE  = (string)Application.Current.Resources["NotifyUserExistsEN"];
            string messageSE  = (string)Application.Current.Resources["NotifyServerErrorEN"];
            string messageEF  = (string)Application.Current.Resources["NotifyEmptyFieldsEN"];

            if (Properties.Settings.Default.DefaultLanguage.Equals(new CultureInfo("ru-RU")))
            {
                badgeError = (string)Application.Current.Resources["NotifyErrorBadgeRU"];
                messagePM  = (string)Application.Current.Resources["NotifyPasswordsMismatchRU"];
                messageUE  = (string)Application.Current.Resources["NotifyUserExistsRU"];
                messageSE  = (string)Application.Current.Resources["NotifyServerErrorRU"];
                messageEF  = (string)Application.Current.Resources["NotifyEmptyFieldsRU"];
            }

            if (password != confirmPassword)
            {
                Manager.CreateMessage()
                .Accent("#8b0000")
                .Animates(true)
                .AnimationInDuration(0.55)
                .AnimationOutDuration(0.55)
                .Background("#333")
                .HasBadge(badgeError)
                .HasMessage(messagePM)
                .Dismiss().WithDelay(2500)
                .Queue();
                Password.Password = ConfirmPassword.Password = "";
                Password.Focus();
                return;
            }

            if (_login != "" && password != "")
            {
                Loading(true);
                string             hashedPassword = BCrypt.Net.BCrypt.HashPassword(password, 10);
                OperationsResponse response       = await UserOperations.CreateUser(_login, hashedPassword);

                Loading(false);

                switch (response)
                {
                case OperationsResponse.Ok:
                    _userid = await UserOperations.GetUserId(_login);

                    response = await AccountOperations.CreateAccount(_userid, "New user", "undefined");

                    response = await PermissionsOperations.AddPermission(_userid);

                    RegistrationPanel.Visibility  = Visibility.Collapsed;
                    CreateAccountPanel.Visibility = Visibility.Visible;
                    break;

                case OperationsResponse.UserExists:
                    Manager.CreateMessage()
                    .Accent("#8b0000")
                    .Animates(true)
                    .AnimationInDuration(0.55)
                    .AnimationOutDuration(0.55)
                    .Background("#333")
                    .HasBadge(badgeError)
                    .HasMessage(messageUE)
                    .Dismiss().WithDelay(2500)
                    .Queue();
                    break;

                case OperationsResponse.ServerError:
                    Manager.CreateMessage()
                    .Accent("#8b0000")
                    .Animates(true)
                    .AnimationInDuration(0.55)
                    .AnimationOutDuration(0.55)
                    .Background("#333")
                    .HasBadge(badgeError)
                    .HasMessage(messageSE)
                    .Dismiss().WithDelay(2500)
                    .Queue();
                    break;
                }
            }
            else
            {
                Manager.CreateMessage()
                .Accent("DeepSkyBlue")
                .Animates(true)
                .AnimationInDuration(0.55)
                .AnimationOutDuration(0.55)
                .Background("#333")
                .HasBadge(badgeError)
                .HasMessage(messageEF)
                .Dismiss().WithDelay(2500)
                .Queue();
            }
        } // функция регистрации