... | ... |
@@ -21,7 +21,6 @@ sub create_project { |
21 | 21 |
eval { $self->_create_project($user, $project) }; |
22 | 22 |
croak $error = $@ if $@; |
23 | 23 |
eval {$self->_create_rep($user, $project, $opts) }; |
24 |
- $error->{message} = $@; |
|
25 | 24 |
croak $error = $@ if $@; |
26 | 25 |
}); |
27 | 26 |
}; |
... | ... |
@@ -40,7 +39,6 @@ sub delete_project { |
40 | 39 |
eval { $self->_delete_project($user, $project) }; |
41 | 40 |
croak $error = $@ if $@; |
42 | 41 |
eval {$self->_delete_rep($user, $project) }; |
43 |
- $error->{message} = $@; |
|
44 | 42 |
croak $error = $@ if $@; |
45 | 43 |
}); |
46 | 44 |
}; |
... | ... |
@@ -49,6 +47,38 @@ sub delete_project { |
49 | 47 |
return 1; |
50 | 48 |
} |
51 | 49 |
|
50 |
+sub create_user { |
|
51 |
+ my ($self, $user, $data) = @_; |
|
52 |
+ |
|
53 |
+ my $dbi = $self->app->dbi; |
|
54 |
+ |
|
55 |
+ # Create user |
|
56 |
+ my $error; |
|
57 |
+ eval { |
|
58 |
+ $dbi->connector->txn(sub { |
|
59 |
+ eval { $self->_create_db_user($user, $data) }; |
|
60 |
+ croak $error = $@ if $@; |
|
61 |
+ eval {$self->_create_user_dir($user) }; |
|
62 |
+ croak $error = $@ if $@; |
|
63 |
+ }); |
|
64 |
+ }; |
|
65 |
+ croak $error if $@; |
|
66 |
+} |
|
67 |
+ |
|
68 |
+sub _create_db_user { |
|
69 |
+ my ($self, $user, $data) = @_; |
|
70 |
+ |
|
71 |
+ $self->app->dbi->model('user')->insert($data, id => $user); |
|
72 |
+} |
|
73 |
+ |
|
74 |
+sub _create_user_dir { |
|
75 |
+ my ($self, $user) = @_; |
|
76 |
+ |
|
77 |
+ my $home = $self->app->git->rep_home; |
|
78 |
+ my $user_dir = "$home/$user"; |
|
79 |
+ mkpath $user_dir; |
|
80 |
+} |
|
81 |
+ |
|
52 | 82 |
sub exists_project { shift->_exists_project(@_) } |
53 | 83 |
|
54 | 84 |
sub fork_project { |
... | ... |
@@ -42,11 +42,16 @@ |
42 | 42 |
$valid_params->{password} = md5_sum $valid_params->{password}; |
43 | 43 |
my $config_json = $api->json($valid_params); |
44 | 44 |
|
45 |
- $self->app->dbi->model('user')->insert({id => $id, config => $config_json}); |
|
46 |
- |
|
47 |
- $self->flash(success => 1); |
|
48 |
- $self->flash(id => $id); |
|
49 |
- $self->redirect_to('current'); |
|
45 |
+ eval { app->manager->create_user($id, {config => $config_json}) }; |
|
46 |
+ if ($@) { |
|
47 |
+ app->log->error($@); |
|
48 |
+ $errors = ['Internal Error']; |
|
49 |
+ } |
|
50 |
+ else { |
|
51 |
+ $self->flash(success => 1); |
|
52 |
+ $self->flash(id => $id); |
|
53 |
+ $self->redirect_to('current'); |
|
54 |
+ } |
|
50 | 55 |
} |
51 | 56 |
else { |
52 | 57 |
$state = 'error'; |
... | ... |
@@ -62,13 +67,21 @@ |
62 | 67 |
<div class="container"> |
63 | 68 |
% my $id = ''; |
64 | 69 |
% if (flash('success')) { |
65 |
- |
|
66 | 70 |
<div class="alert alert-success"> |
67 | 71 |
<button type="button" class="close" data-dismiss="alert">×</button> |
68 | 72 |
Success: User <b><%= flash('id') %></b> is created. |
69 | 73 |
</div> |
70 | 74 |
% } |
71 |
- |
|
75 |
+ |
|
76 |
+ % if ($errors) { |
|
77 |
+ <div class="alert"> |
|
78 |
+ <button type="button" class="close" data-dismiss="alert">×</button> |
|
79 |
+ % for my $error (@$errors) { |
|
80 |
+ <p><%= $error %></p> |
|
81 |
+ % } |
|
82 |
+ </div> |
|
83 |
+ % } |
|
84 |
+ |
|
72 | 85 |
<div class="text-center"><h3>Create User</h3></div> |
73 | 86 |
<div class="well" style="background-color:white;padding-top:15px;padding-left:60px;width:300px;margin-left:auto;margin-right:auto"> |
74 | 87 |
<form action="<%= url_for->query(op => 'create') %>" method="post"> |