summaryrefslogtreecommitdiff
path: root/app/php/pages
diff options
context:
space:
mode:
Diffstat (limited to 'app/php/pages')
-rw-r--r--app/php/pages/Admin.page1
-rw-r--r--app/php/pages/Admin.php7
-rw-r--r--app/php/pages/Login.page17
-rw-r--r--app/php/pages/Login.php20
-rw-r--r--app/php/pages/Profile.page1
-rw-r--r--app/php/pages/Profile.php7
-rw-r--r--app/php/pages/Signup.page37
-rw-r--r--app/php/pages/Signup.php27
-rw-r--r--app/php/pages/config.xml7
9 files changed, 124 insertions, 0 deletions
diff --git a/app/php/pages/Admin.page b/app/php/pages/Admin.page
new file mode 100644
index 0000000..431a6fb
--- /dev/null
+++ b/app/php/pages/Admin.page
@@ -0,0 +1 @@
+Page
diff --git a/app/php/pages/Admin.php b/app/php/pages/Admin.php
new file mode 100644
index 0000000..3e8ee1a
--- /dev/null
+++ b/app/php/pages/Admin.php
@@ -0,0 +1,7 @@
+<?php
+
+class Admin extends TPage {
+
+}
+
+?>
diff --git a/app/php/pages/Login.page b/app/php/pages/Login.page
new file mode 100644
index 0000000..d0825a0
--- /dev/null
+++ b/app/php/pages/Login.page
@@ -0,0 +1,17 @@
+<com:TForm>
+ Username: <com:TTextBox ID="Login" />
+ <com:TRequiredFieldValidator ControlToValidate="Login"
+ Display="Dynamic"
+ ErrorMessage="Username cannot be empty" />
+ <br />
+ Password: <com:TTextBox ID="Password" TextMode="Password" />
+ <com:TRequiredFieldValidator ControlToValidate="Password"
+ Display="Dynamic"
+ ErrorMessage="Password cannot be empty" />
+ <com:TCustomValidator ControlToValidate="Password"
+ OnServerValidate="validatePassword"
+ Display="Dynamic"
+ ErrorMessage="Username and password don't match" />
+ <br />
+ <com:TButton Text="Login" OnCommand="loginUser" />
+</com:TForm>
diff --git a/app/php/pages/Login.php b/app/php/pages/Login.php
new file mode 100644
index 0000000..d7be42b
--- /dev/null
+++ b/app/php/pages/Login.php
@@ -0,0 +1,20 @@
+<?php
+
+class Login extends TPage {
+
+ public function loginUser($sender, $param) {
+ if ($this->Page->IsValid) {
+ $this->Response->redirect(
+ $this->Application->getModule('auth')->ReturnUrl
+ ?: NULL
+ );
+ }
+ }
+
+ public function validatePassword($sender, $param) {
+ $param->IsValid = $this->Application->getModule('auth')->login($this->Login->Text, $this->Password->Text);
+ }
+
+}
+
+?>
diff --git a/app/php/pages/Profile.page b/app/php/pages/Profile.page
new file mode 100644
index 0000000..99455ed
--- /dev/null
+++ b/app/php/pages/Profile.page
@@ -0,0 +1 @@
+Profile
diff --git a/app/php/pages/Profile.php b/app/php/pages/Profile.php
new file mode 100644
index 0000000..fb2c89f
--- /dev/null
+++ b/app/php/pages/Profile.php
@@ -0,0 +1,7 @@
+<?php
+
+class Profile extends TPage {
+
+}
+
+?>
diff --git a/app/php/pages/Signup.page b/app/php/pages/Signup.page
new file mode 100644
index 0000000..0e35da2
--- /dev/null
+++ b/app/php/pages/Signup.page
@@ -0,0 +1,37 @@
+<com:TForm>
+ Username: <com:TTextBox ID="Login" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="Login"
+ Display="Dynamic"
+ ErrorMessage="Username cannot be empty" />
+ <com:TRegularExpressionValidator
+ ControlToValidate="Login"
+ RegularExpression="[a-zA-Z0-9_]{6,255}"
+ Display="Dynamic"
+ ErrorMessage="Username must contain 6-255 characters, all Latin alphanumeric or underscore" />
+ <com:TCustomValidator
+ ControlToValidate="Login"
+ OnServerValidate="checkUsername"
+ Display="Dynamic"
+ ErrorMessage="Username already exists" />
+ <br />
+ Password: <com:TTextBox ID="Password" TextMode="Password" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="Password"
+ Display="Dynamic"
+ ErrorMessage="Password cannot be empty" />
+ <br />
+ Repeat password: <com:TTextBox ID="RePassword" TextMode="Password" />
+ <com:TCompareValidator
+ ControlToValidate="RePassword"
+ ControlToCompare="Password"
+ DataType="String"
+ Operator="Equal"
+ Display="Dynamic"
+ ErrorMessage="Passwords don't match" />
+ <br />
+ Admin: <com:TCheckBox ID="Admin" />
+ <br />
+ <com:TButton Text="Create" OnCommand="registerUser" />
+ <com:TValidationSummary />
+</com:TForm>
diff --git a/app/php/pages/Signup.php b/app/php/pages/Signup.php
new file mode 100644
index 0000000..c999e65
--- /dev/null
+++ b/app/php/pages/Signup.php
@@ -0,0 +1,27 @@
+<?php
+
+Prado::using('Application.model.User');
+
+class Signup extends TPage {
+
+ public function checkUsername($sender, $param) {
+ $param->IsValid = !User::finder()->countByLogin($this->Login->SafeText);
+ }
+
+ public function registerUser($sender, $param) {
+ if ($this->Page->IsValid) {
+ $newUser = new User();
+ $newUser->Login = $this->Login->SafeText;
+ $newUser->Password = password_hash($this->Password->Text, PASSWORD_DEFAULT);
+ $newUser->IsAdmin = $this->Admin->Checked;
+ $newUser->save();
+ $this->Response->redirect($this->Request->constructUrl(
+ $this->Service->ID,
+ NULL
+ ));
+ }
+ }
+
+}
+
+?>
diff --git a/app/php/pages/config.xml b/app/php/pages/config.xml
new file mode 100644
index 0000000..d387667
--- /dev/null
+++ b/app/php/pages/config.xml
@@ -0,0 +1,7 @@
+<configuration>
+ <authorization>
+ <allow pages="Admin,Signup" roles="Admin" />
+ <deny pages="Admin,Signup" />
+ <deny pages="Profile" users="?" />
+ </authorization>
+</configuration>