upload fieldbook from manage phenotyping
[sgn.git] / cgi-bin / solpeople / new-account.pl
blobd1be79766e80bdbe6368029f2f155b357b31fd1a
2 use strict;
4 use CXGN::DB::Connection;
5 use CXGN::Page;
6 use CXGN::Page::FormattingHelpers qw | page_title_html |;
7 use CXGN::People::Login;
8 use CXGN::People::Person;
9 use CXGN::Contact;
11 use CatalystX::GlobalContext '$c';
13 my $page = CXGN::Page->new("solpeople create account", "Koni");
14 my $dbh = CXGN::DB::Connection->new();
16 my $conf = $c->config;
18 if ($conf->{is_mirror}) {
19 $page->message_page("This site is a mirror site and does not support adding users. Please go to the main site to create an account.");
23 my ($first_name, $last_name, $username, $password, $confirm_password, $email_address, $organization)
24 = $page->get_arguments(qw(first_name last_name username password confirm_password email_address organization));
26 if ($username) {
28 # check password properties...
30 my @fail = ();
31 if (length($username) < 7) {
32 push @fail, "Username is too short. Username must be 7 or more characters";
33 } else {
34 # does user already exist?
36 my $existing_login = CXGN::People::Login -> get_login($dbh, $username);
38 if ($existing_login->get_username()) {
39 push @fail, "Username \"$username\" is already in use. Please pick a different username.";
43 if (length($password) < 7) {
44 push @fail, "Password is too short. Password must be 7 or more characters";
46 if ("$password" ne "$confirm_password") {
47 push @fail, "Password and confirm password do not match.";
50 if (!$organization) {
51 push @fail, "'Organization' is required.'";
54 if ($password eq $username) {
55 push @fail, "Password must not be the same as your username.";
57 if ($email_address !~ m/[^\@]+\@[^\@]+/) {
58 push @fail, "Email address is invalid.";
60 unless($first_name) {
61 push @fail,"You must enter a first name or initial.";
63 unless($last_name) {
64 push @fail,"You must enter a last name.";
67 if (@fail) {
69 #$page->message_page("Account could not be created ".(join " ", @fail));
71 &show_fail_reasons(\@fail, $page);
72 exit();
77 my $confirm_code = $page->tempname();
78 my $new_user = CXGN::People::Login->new($dbh);
79 $new_user -> set_username($username);
80 $new_user -> set_password($password);
81 $new_user -> set_pending_email($email_address);
82 $new_user -> set_confirm_code($confirm_code);
83 $new_user -> set_disabled('unconfirmed account');
84 $new_user -> set_organization($organization);
85 $new_user -> store();
87 #this is being added because the person object still uses two different objects, despite the fact that we've merged the tables
88 my $person_id=$new_user->get_sp_person_id();
89 my $new_person=CXGN::People::Person->new($dbh,$person_id);
90 $new_person->set_first_name($first_name);
91 $new_person->set_last_name($last_name);
92 $new_person->store();
94 my $host = CGI->new->server_name;
95 my $subject="[SGN] Email Address Confirmation Request";
96 my $body=<<END_HEREDOC;
98 Please do *NOT* reply to this message. The return address is not valid.
99 Use sgn-feedback\@solgenomics.net instead.
101 This message is sent to confirm the email address for community user
102 \"$username\"
104 Please click (or cut and paste into your browser) the following link to
105 confirm your account and email address:
107 http://$host/solpeople/account-confirm.pl?username=$username&confirm=$confirm_code
109 Thank you,
110 Sol Genomics Network
112 END_HEREDOC
114 CXGN::Contact::send_email($subject,$body,$email_address);
118 $page->header();
120 print page_title_html("Create New Account");
122 print <<END_HEREDOC;
124 <table summary="" width="80%" align="center">
125 <tr><td><p>Account was created with username \"$username\". To continue, you must confirm that SGN staff can reach you via email address \"$email_address\". An email has been sent with a URL to confirm this address. Please check your email for this message and use the link to confirm your email address.</p></td></tr>
126 <tr><td><br /></td></tr>
127 </table>
129 END_HEREDOC
131 $page->footer();
133 } else {
135 $page->header();
138 print page_title_html("Create New Account");
140 print <<END_HEREDOC;
143 <!--
144 <div class='boxbgcolor5'><b>Please note:</b></a><br />
147 <ul>
149 <li><b>Before</b> creating a new account, please check if you <b>already have an account</b> using the <a href="/search/direct_search.pl?search=directory">directory search</a>. </li>
150 <li>A link will be emailed to you. Please click on it to activate the account.</li>
151 <li><b>All fields are required.</b></li>
152 </div>
155 <div class="container-fluid">
156 <div class="row">
157 <div class="col-sm-2 col-md-2 col-lg-2">
158 </div>
159 <div class="col-sm-8 col-md-8 col-lg-8" >
160 <div class="panel panel-danger">
161 <div class="panel-heading">Notice</div>
162 <div class="panel-body">
163 <ul>
164 <li><b>Before</b> creating a new account, please check if you <b>already have an account</b> using the <a href="/search/direct_search.pl?search=directory">directory search</a>. </li>
165 <li>A link will be emailed to you. Please click on it to activate the account.</li>
166 <li><b>All fields are required.</b></li>
167 </ul>
168 </div>
169 </div>
171 <form class="form-horizontal" role="form" name="submit_userdata" method="post" action="new-account.pl">
172 <div class="form-group">
173 <label class="col-sm-3 control-label">First Name: </label>
174 <div class="col-sm-9">
175 <input class="form-control" type="text" name="first_name" value="" />
176 </div>
177 </div>
178 <div class="form-group">
179 <label class="col-sm-3 control-label">Last Name: </label>
180 <div class="col-sm-9">
181 <input class="form-control" type="text" name="last_name" value="" />
182 </div>
183 </div>
184 <div class="form-group">
185 <label class="col-sm-3 control-label">Organization: </label>
186 <div class="col-sm-9">
187 <input class="form-control" type="text" name="organization" value="" />
188 </div>
189 </div>
190 <div class="form-group">
191 <label class="col-sm-3 control-label">Username: </label>
192 <div class="col-sm-9">
193 <input class="form-control" type="text" name="username" value="" /><br/>Username must be at least 7 characters long.
194 </div>
195 </div>
196 <div class="form-group">
197 <label class="col-sm-3 control-label">Password: </label>
198 <div class="col-sm-9">
199 <input class="form-control" type="password" name="password" value="" /><br/>Password must be at least 7 characters long and different from your username.
200 </div>
201 </div>
202 <div class="form-group">
203 <label class="col-sm-3 control-label">Confirm Password: </label>
204 <div class="col-sm-9">
205 <input class="form-control" type="password" name="confirm_password" value="" />
206 </div>
207 </div>
208 <div class="form-group">
209 <label class="col-sm-3 control-label">Email Address: </label>
210 <div class="col-sm-9">
211 <input class="form-control" type="text" name="email_address" value="" /><br/>An email will be sent to this address requiring you to confirm its receipt to activate your account.<br/>
212 </div>
213 </div>
214 <div align="right">
215 <button class="btn btn-default" type="reset" >Reset</button>
216 <button class="btn btn-primary" type="submit" name="create_account" value="Create Account" >Create Account</button>
217 </div>
218 </form>
219 </div>
220 <div class="col-sm-2 col-md-2 col-lg-2">
221 </div>
222 </div>
223 </div>
224 <br/>
226 <!--
227 <form name="submit_userdata" method="post" action="new-account.pl">
228 <table summary="" cellpadding="2" cellspacing="2" width="80%" align="center">
230 <tr><td colspan="2"><br /></td></tr>
231 <tr><td>First name</td><td><input type="text" name="first_name" size="40" value="" /></td></tr>
232 <tr><td>Last name</td><td><input type="text" name="last_name" size="40" value="" /></td></tr>
233 <tr><td>Organization</td><td><input type="text" name="organization" size="40" value="" /></td></tr>
234 <tr><td>Username</td><td><input type="text" name="username" size="12" value="" /></td></tr>
235 <tr><td colspan="2" style="font-size: 80%">Username must be at least 7 characters long.</td></tr>
236 <tr><td>Password</td><td><input type="password" name="password" size="12" value="" /></td></tr>
237 <tr><td colspan="2" style="font-size: 80%">Password must be at least 7 characters long and different from your username.</td></tr>
238 <tr><td>Confirm Password</td><td><input type="password" name="confirm_password" size="12" value="" /></td></tr>
239 <tr><td colspan="2"><br /></td></tr>
240 <tr><td>Email Address</td><td><input type="text" name="email_address" size="40" value="" /></td></tr>
241 <tr><td colspan="2" style="font-size: 80%">An email will be sent to this address requiring you to confirm its receipt to activate your account.<br /><br /><br /></td></tr>
243 <tr><td><input type="reset" /></td><td align="right"><input type="submit" name="create_account" value="Create Account" /></td></tr>
244 </table>
245 </form>
248 END_HEREDOC
250 $page->footer();
254 sub show_fail_reasons {
255 my $fail_ref = shift;
256 my $p = shift;
258 my $fail_str = "";
259 foreach my $s (@$fail_ref) {
260 $fail_str .= "<li>$s</li>\n"
264 $p->header();
267 print <<END_HEREDOC;
269 <table summary="" width="80%" align="center">
270 <tr><td>
271 <p>Your account could not be created for the following reasons</p>
273 <ul>
274 $fail_str
275 </ul>
277 <p>Please use your browser\'s back button to try again.</p>
278 </td></tr>
279 <tr><td><br /></td></tr>
280 </table>
282 END_HEREDOC
284 $p->footer();