diff mackey/academy/add.rb @ 2403:2ee6e6efc0dd

Mackey academy added
author MASAHIRO Suzuki <c112085@roy.e.koeki-u.ac.jp>
date Fri, 09 Jan 2015 15:18:12 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mackey/academy/add.rb	Fri Jan 09 15:18:12 2015 +0900
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+# coding: euc-jp
+require 'rubygems'
+require 'pg'
+require 'cgi'
+c = CGI.new(:accept_charset => "euc-jp")
+print"Content-type: text/html; charset=euc-jp\n\n"
+
+number = c["id"]
+pswd = c["pass"]
+namae = c["name"]
+sx = c["sex"]
+check = 0
+
+begin
+  conn = PGconn.connect('broy.e.koeki-u.ac.jp','','','','c112085','mackeyacademy','l3nl3q1u')
+  a = "select id from userdata"
+  ip = conn.exec(a)
+  ip.each do |row|
+    if number == row["id"]
+      check = 1 
+    end
+  end
+  if check == 0
+    q = "insert into userdata (id, password, name, sex, level, exp, quest) values ('#{number}', '#{pswd}', '#{namae}', '#{sx}', '1', '0', '0')"
+    export = conn.exec(q)
+  end
+end
+print"<html>
+<head>
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\">
+<title>ユーザー登録</title>
+<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
+</head>
+<body>\n"
+if check == 0
+  print"<h1>登録完了</h1>
+<a href=\"login.html\">
+<button class=\"css3button\">ログイン</button>\n"
+elsif check == 1
+  print"<h1>Error</h1>
+<p>既にIDが使われています</p>
+<a href=\"add.html\">
+<button class=\"css3button\">もう一度</button>\n"
+end
+print"</a>
+</body>
+</html>\n"

yatex.org