view opencampus2015/accountcheck.rb @ 2600:977564cb67bc

rm
author ARAKI Tsuyohito <c113007@e.koeki-u.ac.jp>
date Fri, 23 Oct 2015 13:21:03 +0900
parents 518898bed878
children 667f8ae73792
line wrap: on
line source

#!/usr/bin/env ruby22
# -*- coding: utf-8 -*-

require 'sqlite3'
require 'kconv'
require 'cgi'

c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8")
db = SQLite3::Database.new("sql/main.sq3")


sql = "insert into test values(?, ?, ?, ?, ?, ?, ?, ?, ?)"

toi = "insert into toi values (?, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)"
item = "insert into goods values (?, 0, 0, 0, 0, 0, 0)"

name = c["name"]
pswd = c["pswd"]
cle1 = "CREATE TABLE IF NOT EXISTS test(id, name, cal, age, sex, pswd, exp, pt, lv)"
cle2 = "CREATE TABLE IF NOT EXISTS toi(id, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10)"
cle3 = "CREATE TABLE IF NOT EXISTS goods(id, g1, g2, g3, g4, g5, g6)"
cle4 = "CREATE TABLE IF NOT EXISTS time(cd, now, id)"
cle5 = "CREATE TABLE IF NOT EXISTS num(cd, id)"
cle6 = "CREATE TABLE IF NOT EXISTS pass(id, pass, name)"

cle7 = "CREATE TABLE IF NOT EXISTS zukan(no, name, tah, lv2, lv3, lv4, lv5)"
cle8 = "CREATE TABLE IF NOT EXISTS box(id, i1, e1, t1,tm1, i2, e2, t2, tm2, i3, e3, t3, tm3)"
#ins8 = ".import list.csv zukan"

ins4 = 'insert into time values(?, 61, "n")'
ins5 = 'insert into num values("aa",0)'
ins6 = 'insert into pass values(?, ?, ?)'
num = "select id from num where cd = ?"
numup = "update num set id = ? where cd = ?"

db.execute(cle1)
db.execute(cle2)
#db.execute(cle3)
db.execute(cle4)
db.execute(cle5)
db.execute(cle6)
db.execute(cle7)
db.execute(cle8)
if name == "createman789789789"
db.execute(ins4, "a")
db.execute(ins4, "b")
db.execute(ins4, "c")
db.execute(ins4, "d")
db.execute(ins4, "e")
db.execute(ins4, "f")
db.execute(ins4, "g")
db.execute(ins4, "h")
db.execute(ins4, "i")
db.execute(ins4, "j")
db.execute(ins5)
system `sqlite3 -separator , /sql/main.sq3 ".import list.csv zukan"` #(cle8)
end

name = c["name"]
namae = "#{name}"
cal = c["cal"]
age = c["age"]
sex = c["sex"]
aria = c["aria"]

id = c.cookies["id"][0]
pass = c.cookies["pass"][0]

if id == nil
  number = db.execute(num, "aa")
begin
  id = number[0][0].to_i + 1
rescue
  db.execute(ins4, "a")
  db.execute(ins4, "b")
  db.execute(ins4, "c")
  db.execute(ins4, "d")
  db.execute(ins4, "e")
  db.execute(ins4, "f")
  db.execute(ins4, "g")
  db.execute(ins4, "h")
  db.execute(ins4, "i")
  db.execute(ins4, "j")
  db.execute(ins5)
  id = number[0][0].to_i + 1
end
  exp = 0
  pt = 0
  lv = 1
  cd = "aa"
  if pass == nil
    pass = id
  end
  db.execute(ins6, id, pass, name)
  db.execute(sql, id, name, cal, age, sex, aria, exp, pt, lv)
  db.execute(toi, id)
#  db.execute(item, id)
  db.execute(numup, id, cd)
end
#  srand(id.to_i)  
#  id2 = rand(1000000)
id2 = pass



expires = "SAT, 24 Oct 2015 00:00:00 GMT"

printf("Content-type: text/html; charset=UTF-8
Set-Cookie:id=%s ;expires=%s
Set-Cookie:pass=%s ;expires=%s\n\n", id, expires, id2, expires)

printf(<<_EOS_, name, id.to_i)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<link media="only screen and (max-device-width:480px)" href="smart.css" type="text/css" rel="stylesheet" />
<link media="screen and (min-device-width:481px)" href="profeel.css" type="text/css" rel="stylesheet" />




<link rel="shortcut icon" href="./img/cabage.png"/>
<title>Registering Account</title>

</head>
<body>
<h1>Miyazac Quest</h1>
<h2>登録完了!</h2>
<p>よくきた_ %s _よ!</p>
<p>おまえのIDは%04dだ!</p>
<div class="f1"><a href="prof.rb"><div class="lets"><span>始めよう!</span></div></a></div>
<form method="POST" type="text">
</form>
</body></html>
_EOS_


if name == "createman987987987"
  `rm sql/main.sq3`
#  `touch sql/main.sq3`
#  `chmod a+w sql/main.sq3`
end

yatex.org