Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <web-client> master : simple validation for e-mail and 2 password fields
  • From: Jiri Suchomel <jsuchome@xxxxxxx>
  • Date: Wed, 16 Sep 2009 14:59:39 +0200
  • Message-id: <E1MoC7q-0003v5-VI@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 25461f0a85cde0eeebae789c75d367f100a72e66
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Wed Sep 16 14:59:39 2009 +0200

simple validation for e-mail and 2 password fields
---
.../app/controllers/administrator_controller.rb | 17 +++++++++++++
.../app/views/administrator/index.html.erb | 25 ++++++++++++++++++-
2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/plugins/administrator/app/controllers/administrator_controller.rb
b/plugins/administrator/app/controllers/administrator_controller.rb
index 7dbef43..6d63764 100644
--- a/plugins/administrator/app/controllers/administrator_controller.rb
+++ b/plugins/administrator/app/controllers/administrator_controller.rb
@@ -22,6 +22,7 @@ class AdministratorController < ApplicationController
def index
return unless client_permissions
@administrator = @client.find
+ @administrator.confirm_password = ""
end

# PUT
@@ -33,6 +34,19 @@ class AdministratorController < ApplicationController
@administrator.password = admin["password"]
@administrator.aliases = admin["aliases"]

+ # FIXME validate for set of mails, not just one
+ if !admin["aliases"].empty? && admin["aliases"] !~ /(.+)@(.+)\.(.{2})/ #
yes, very weak
+ flash[:error] = _("Enter a valid e-mail address.")
+ redirect_to :action => "index"
+ return
+ end
+
+ if admin["password"] != admin["confirm_password"]
+ flash[:error] = _("Passwords do not match.")
+ redirect_to :action => "index"
+ return
+ end
+
# only save selected subset of administrator data:
if params.has_key? "save_aliases"
@administrator.password = nil
@@ -40,6 +54,9 @@ class AdministratorController < ApplicationController
@administrator.aliases = nil
end

+ # we cannot pass empty string to rest-service
+ @administrator.aliases = "NONE" if @administrator.aliases == ""
+
begin
response = @administrator.save
rescue ActiveResource::ClientError => e
diff --git a/plugins/administrator/app/views/administrator/index.html.erb
b/plugins/administrator/app/views/administrator/index.html.erb
index 4423d80..9928e80 100644
--- a/plugins/administrator/app/views/administrator/index.html.erb
+++ b/plugins/administrator/app/views/administrator/index.html.erb
@@ -1,21 +1,42 @@
<div class='plugin-icon'><img src='/icons/yast-users.png'/></div>

+<script src="http://code.jquery.com/jquery-latest.js";></script>
+<script type="text/javascript"
src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js";></script>
+<style type="text/css">
+ * { font-family: Verdana; font-size: 96%; }
+ label { width: 10em; float: left; }
+ label.error { float: none; color: red; padding-left: .5em; vertical-align:
top; }
+ p { clear: both; }
+ .submit { margin-left: 12em; }
+ em { font-weight: bold; padding-right: 1em; vertical-align: top; }
+</style>
+<script>
+ $(document).ready(function(){
+ $("#adminForm").validate();
+ });
+</script>
+
+
<h2><%=_("Administrator Settings")%></h2>

<% disabled = ! @permissions[:write] %>

<div class="table">
<table class="list">
- <% form_for(:administrator, @administrator, :url => { :action => "update" },
:html => { :method => :put } ) do |f| %>
+ <% form_for(:administrator, @administrator, :url => { :action => "update" },
:html => { :method => :put, :id => "adminForm" } ) do |f| %>
<%= f.error_messages %>
<tr class="bg">
<td class="first"><strong><%=_("Password")%></strong></td>
<td class="last"><%= f.password_field :password, :disabled => disabled
%></td>
+ </tr>
+ <tr class="bg">
+ <td class="first"><strong><%=_("Confirm Password")%></strong></td>
+ <td class="last"><%= f.password_field :confirm_password, :disabled =>
disabled, :equalTo => "#administrator_password" %></td>
<td><%= f.submit _("Save"), :name => "save_password", :disabled =>
disabled %></td>
</tr>
<tr class="bg">
<td class="first"><strong><%=_("Forward mail to")%></strong></td>
- <td class="last"><%= f.text_field :aliases, :disabled => disabled
%></td>
+ <td class="last"><%= f.text_field :aliases, :disabled => disabled,
:class => "email" %></td>
<td><%= f.submit _("Save"), :name => "save_aliases", :disabled =>
disabled %></td>
</tr>
<tr>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages