Post by votan on Aug 15, 2008 8:51:58 GMT -5
This is a user-registration / newsletter tool. I only started this for teaching myself some RB... so this program is anything else but well structured or clean! I would call it "patchwork-code" as it basically only consists of segments from the building blocks and tutorials found on the wiki.
I'm sure there are many things that can be done way easier or faster.. but I don't know better yet. Ok, let me describe what this program is....
It's basically a registration tool, where users can register themself, chosing a username, password and email address. The system then sends out a confirmation email that contains a link thet needs to be clicked to actually become a verified user.
I tried to implement all sorts of error checking to make registering foolproof.. not sure if I thought of all things possible though....
I also implemented a send-email tool in the admin panel. It might even be better for using it as a newsletter system!? Just change "username", "password" to "first name", "last name" and you have a fully working newsletter system. Unfortunately the smtp handler is not so cool right now.... so I can't set a realname for the emailsender, nor can I check the status of the emails being send.... so no way right now to see if all users have already been mailed or not...
Anyway, this is just a noob script.... actually my first selfwritten program ever... so don't be to mean on critics.... but let me know what I can do better...
here a closer list of what it does:
- check if all data have been entered
- check if email is in a valid format
- check if domain extension is in a list of allowed domains
- password protected admin panel
- all settings are changeable through the admin panel
- requires users to verify their registrations through email link
- send out emails to all verified users
- registration with captcha verification
- captcha generates code of random length, random characters, random font and style
- etc
know issues...
- passwords are stored unencrypted.
- smtp handler lacks some things
- no errorcheck when changing settings
- I probably used to many variables and set to many global (was to lazy to clean that out again)
Installation:
Copy code into a blank project. Save project as "register"
Publish project.
Call project by http://localhost:8008/seaside/go/runbasicpersonal?app=register (if you installed RB the default way)
Finish the little installer (basically just checks some default variables and creates the DB)
Requires at least RB 1.01 beta2 .... code might need some changes if you didn't install RB in the default dir.
Default password for admin panel is admin
Use at your own risk....
I'm sure there are many things that can be done way easier or faster.. but I don't know better yet. Ok, let me describe what this program is....
It's basically a registration tool, where users can register themself, chosing a username, password and email address. The system then sends out a confirmation email that contains a link thet needs to be clicked to actually become a verified user.
I tried to implement all sorts of error checking to make registering foolproof.. not sure if I thought of all things possible though....
I also implemented a send-email tool in the admin panel. It might even be better for using it as a newsletter system!? Just change "username", "password" to "first name", "last name" and you have a fully working newsletter system. Unfortunately the smtp handler is not so cool right now.... so I can't set a realname for the emailsender, nor can I check the status of the emails being send.... so no way right now to see if all users have already been mailed or not...
Anyway, this is just a noob script.... actually my first selfwritten program ever... so don't be to mean on critics.... but let me know what I can do better...
here a closer list of what it does:
- check if all data have been entered
- check if email is in a valid format
- check if domain extension is in a list of allowed domains
- password protected admin panel
- all settings are changeable through the admin panel
- requires users to verify their registrations through email link
- send out emails to all verified users
- registration with captcha verification
- captcha generates code of random length, random characters, random font and style
- etc
know issues...
- passwords are stored unencrypted.
- smtp handler lacks some things
- no errorcheck when changing settings
- I probably used to many variables and set to many global (was to lazy to clean that out again)
Installation:
Copy code into a blank project. Save project as "register"
Publish project.
Call project by http://localhost:8008/seaside/go/runbasicpersonal?app=register (if you installed RB the default way)
Finish the little installer (basically just checks some default variables and creates the DB)
Requires at least RB 1.01 beta2 .... code might need some changes if you didn't install RB in the default dir.
Default password for admin panel is admin
Use at your own risk....
'this is a little program that can be used for handling subscriptions / registrations for membership site
'like forums, galleries or whatever. It can also be used as a fully functional newsletter system.
'of cause, some limitations apply, as the RB smtp handler is not the best right now.
'if you really put the program on the net, better remove the "manage" link from the registrationpage.
'and instead access the admin panel through a link like "runbasicpersonal?app=register5&manage"
'you can define the name of the admin panel (manage by default) in the admin panel / settings
'This is only a stupid example of what a noob like me can do with runbasic... so use on your own risk!
'Read more in the forum where you got this script from!
'default password for the admin panel is "admin"
on error goto [errorhandler]
'--some variables settings
login = 0
global #username, #password, #email, i, userdate, useremail$, username$, captcha$, #captchacode, captchacode$, mailserver$, pword$, fromaddr$, subject$, emailtext$, emailcode$, atvalue, usecaptcha, #cleardays, clearscreen, #subject, #text, errorid$, login, adminpassword$, #adminpassword, rf, a$, b$,
'-- some simple design
cssClass "table", "{ width: 400px; text-align:left;border-style:solid;border-width:1px;border-color:#000000;}"
cssClass "tr", "{ background: #cccccc; padding: 3px }"
cssClass "td", "{width:45%;}"
'-- invoke initial setup, if DB is not yet present
files #fe, "register.db"
if #fe HASANSWER() = 0 then
html "<div align = 'center'>"
html "<h1>Initial setup</h1>"
print "Full URL to the app : ";
textbox #apppath, "http://localhost:8008/seaside/go/runbasicpersonal?app=register", 50
html "<br>"
print "mailserver address : ";
textbox #mailserver, "mail.yourserver.com", 50
html "<br>"
print "mailserver from-address : ";
textbox #fromaddress, "rbtest@yourserver.com", 50
html "<br>"
print "mailserver password : ";
textbox #password, "rbtest", 50
html "<br>"
print "admin password : ";
textbox #adminpassword, "admin", 50
html "<br>"
button #submit, "Submit", [createdb]
html "</div>"
wait
end if
'-- create DB if DB is not present
[createdb]
files #fe, "register.db"
if #fe HASANSWER() = 0 then
apppath$ = #apppath contents$()
mailserver$ = #mailserver contents$()
fromaddr$ = #fromaddress contents$()
password$ = #password contents$()
adminpassword$ = #adminpassword contents$()
sqliteconnect #mySQLdb, "register.db"
action$ = "create table users (user_id integer primary key autoincrement, user_name TEXT, user_password TEXT, user_email TEXT, joindate NUMERIC, email_code TEXT, verified NUMERIC)"
#mySQLdb execute(action$)
action$ = "create table settings (app_path TEXT, use_captcha NUMERIC, mailserver_emailtext TEXT, mailserver_emailtext2 TEXT, mailserver_subject TEXT, mailserver_subject2 TEXT, mailserver TEXT, mailserver_fromaddress TEXT, mailserver_password TEXT, allowed_domains TEXT, verification TEXT, administration TEXT, admin_password TEXT)"
#mySQLdb execute(action$)
action$ = "insert into settings (app_path, use_captcha, mailserver_emailtext, mailserver_emailtext2, mailserver_subject, mailserver_subject2, mailserver, mailserver_fromaddress, mailserver_password, allowed_domains, verification, administration, admin_password) values ('"+apppath$+"', 1, ""Thank you for registering at myserver.com.
Please click here to verify your email and to finish the registration: "", ""Welcome to myserver.com.
You are now verified and can access all areas."", ""Complete your registration at myserver.com"", ""Welcome to myserver.com"", '"+mailserver$+"', '"+fromaddr$+"', '"+password$+"', ""com,net,de,fr,uk"", ""verify_email"", ""manage"", '"+adminpassword$+"')"
#mySQLdb execute(action$)
#mySQLdb disconnect()
end if
'-- Read the config from the DB
[readconfig]
sqliteconnect #mySQLdb, "register.db" ' Connect to the DB
sql$ = "SELECT * FROM settings LIMIT 1"
#mySQLdb execute(sql$)
result$ = #mySQLdb nextrow$("|")
fields$ = #mySQLdb columnnames$()
#mySQLdb disconnect()
rf = 1
WHILE word$(fields$,rf,",") <> ""
a$ = trim$(word$(fields$,rf,","))
b$ = trim$(word$(result$,rf,"|"))
if a$ = "app_path" then apppath$ = b$ '--full url to the app
if a$ = "verification" then verifyname$ = b$ '--name of the verification email link
if a$ = "administration" then managename$ = b$ '--name of the administration link
if a$ = "mailserver" then mailserver$ = b$ '--address of your mailserver
if a$ = "mailserver_password" then pword$ = b$ '--mailserver password
if a$ = "mailserver_fromaddress" then fromaddr$ = b$ '--your email address, used as the return address
if a$ = "mailserver_subject" then subject$ = b$ '--verification email subject
if a$ = "mailserver_subject2" then subject2$ = b$ '--welcome email subject
if a$ = "mailserver_emailtext" then emailtext$ = b$ '--verification email text
if a$ = "mailserver_emailtext2" then emailtext2$ = b$ '--verification email text
if a$ = "use_captcha" then usecaptcha = val(b$)
if a$ = "admin_password" then adminpassword$ = b$
rf = rf + 1
WEND
if applysettings = 1 then
applysettings = 0
goto [manage]
end if
'--check for verifiaction requests or if you want to manage the system
if instr(UrlKeys$,verifyname$) > 0 then [verify]
if instr(UrlKeys$,managename$) > 0 then [manage]
'-- here we have the registration interface
[main]
errorid$ = "main"
cls
html "<h1 align = 'center'>Registration</h1>"
html "<p align = 'center'>"
html "<font color = 'red'>"
print formerror$
formerror$ = ""
html "</font>"
html "</p>"
html "<table align = 'center' border = '1'>"
html "<tr>"
html "<td align = 'center' valign = 'top'>"
print "Username : ";
textbox #username, username$
html "<br>"
print "Password : ";
textbox #password, userpassword$
html "<br>"
print "Emailaddr: ";
textbox #email, useremail$
html "<br>"
if usecaptcha=1 then
print captchafunc$()
print "captcha. : ";
textbox #captchacode, ""
html "<br>"
button #refresh, "new captcha", [main]
print " ";
end if
button #submit, "Register", [register]
html "</td>"
html "</tr>"
html "</table>"
html "<br> "
html "<br> "
html "<br> "
html "<table align = 'center' border = '0'>"
html "<tr>"
html "<td align = 'center'>"
button #submit, "Manage", [manage] 'remove this link if putting the program on the net...
html "</td>"
html "</tr>"
html "</table>"
wait
'-- do all the registration work here
[register]
cls
username$ = #username contents$()
userpassword$ = #password contents$()
useremail$ = #email contents$()
userdate = date$("days") ' 36980
if usecaptcha = 1 then captchacode$ = #captchacode contents$()
'-- check captcha code
if usecaptcha = 1 and captchacode$ <> captcha$ then
formerror$ = "Wrong captcha code, please try again."
goto [main]
end if
'-- check if all info is present
if username$ = "" or userpassword$ = "" or useremail$ = "" then
formerror$ = "Please fill in all info!"
goto [main]
end if
'-- check for valid email and correct order of at dot domain
if instr(useremail$,"@") > 0 then
atvalue = instr(useremail$,"@")
goto [checkdomain]
end if
formerror$ = "Sorry, your email is not valid! Please try again."
goto [main]
'-- check if the domain extension is in the list of allowed domains
[checkdomain]
for cd = len(useremail$) to 1 step -1
if instr(useremail$,".",cd) > atvalue then
atvalue = cd
end if
next cd
checkdomain$ = right$(useremail$, len(useremail$) - atvalue)
sqliteconnect #mySQLdb, "register.db"
query$ = "select allowed_domains from settings where allowed_domains like '%"+checkdomain$+"%';"
#mySQLdb execute(query$)
if #mySQLdb hasanswer() then
#mySQLdb disconnect()
goto [dbwrite]
else
formerror$ = "Sorry, your email is not valid! Please try again."
#mySQLdb disconnect()
goto [main]
end if
[dbwrite]
'-- check if email or username is already in use
sqliteconnect #mySQLdb, "register.db"
query$ = "select user_email from users where user_email = '"+useremail$+"';"
#mySQLdb execute(query$)
if #mySQLdb hasanswer() then
formerror$ = "Sorry, this email is already in use."
#mySQLdb disconnect()
goto [main]
end if
query$ = "select user_name from users where user_name = '"+username$+"';"
#mySQLdb execute(query$)
if #mySQLdb hasanswer() then
formerror$ = "Sorry, this username is already in use."
#mySQLdb disconnect()
goto [main]
end if
#mySQLdb disconnect()
'--g enerate unique emailcode
emailcode$ = ""
emailcodelength = 24
for ec = 1 to emailcodelength
ec$ = chr$(int(rnd(1)*26)+97)
emailcode$ = emailcode$ + ec$
next ec
'-- finally this writes the entry to the DB
query$ = "insert into users (user_id, email_code, user_email, joindate, user_name, user_password, verified) values (NULL, '"+emailcode$+"', '"+useremail$+"', (";userdate;"), '"+username$+"', '"+userpassword$+"', 0)"
sqliteconnect #mySQLdb, "register.db"
#mySQLdb execute(query$)
#mySQLdb disconnect()
'--send out the verification mail
gosub [sendemail]
html "<div align = 'center'>"
html "<h1>Confirm your registration</h1>"
print "A confirmation email has been send to " +useremail$
print "Please follow the steps in that email to finish your registration."
html "</div>"
end
'-- this is the function to generate a random captcha
function captchafunc$()
captcha$ = ""
width = 246
height = 49
size = 34
captchalength = int(rnd(1)*4) + 4
for cap = 1 to captchalength
cap$ = chr$(int(rnd(1)*26)+97)
if asc(cap$) = 102 or asc(cap$) = 105 or asc(cap$) = 106 or asc(cap$) = 108 or asc(cap$) = 116 then cap$ = "k"
if asc(cap$) = 109 or asc(cap$) = 111 then cap$ = "n"
captcha$ = captcha$ + cap$
next cap
graphic #CAPTCHA, width, height
#CAPTCHA size(1) 'pen size one
'--loop through the width and height, setting a random color
for y = 0 to height - 1
for x = 0 to width - 1
color = int(rnd(1)*2) + 1
if color = 1 then #CAPTCHA color(0,0,0)
if color = 2 then #CAPTCHA color(255,255,255)
#CAPTCHA set(x,y)
next x
next y
if len(captcha$) = 4 then captchapos = 45
if len(captcha$) = 5 then captchapos = 25
if len(captcha$) = 6 then captchapos = 15
if len(captcha$) = 7 then captchapos = 5
for cap = 1 to captchalength
captchachr$(cap) = mid$(captcha$,cap,1)
fnt = int(rnd(1)*2)+1
if fnt = 1 then fnt$ = "Arial"
if fnt = 2 then fnt$ = "Courier New"
fntstyle = int(rnd(1)*2)+1
if fntstyle = 1 then fntstyle$ = " "
if fntstyle = 2 then fntstyle$ = "Italic"
#CAPTCHA color(255,255,255)
#CAPTCHA place(captchapos,(size + 4))
#CAPTCHA font(fnt$,size,"bold",fntstyle$)
#CAPTCHA "\";captchachr$(cap)
captchapos = captchapos + 35
next cap
render #CAPTCHA
end function
'--check if emailcode and username are valid
[verify]
cls
ikey = 1
while word$(UrlKeys$, ikey, "&") <> ""
option$ = word$(UrlKeys$, ikey, "&")
optionname$ = word$(option$, 1, "=")
optionvalue$ = word$(option$, 2, "=")
if ikey = 2 then verifyname$ = optionvalue$
if ikey = 3 then useremail$ = optionvalue$
ikey = ikey + 1
wend
'--check and update the verifiaction status
sqliteconnect #mySQLdb, "register.db"
query$ = "select user_email, email_code from users where user_email = '"+useremail$+"' and email_code = '"+verifyname$+"' and verified = (";0;")"
#mySQLdb execute(query$)
if #mySQLdb hasanswer() then
action$="update users set verified='";1;"' where user_email = '"+useremail$+"'"
#mySQLdb execute(action$)
#mySQLdb disconnect()
verified = 1
goto [verified]
else
#mySQLdb disconnect()
goto [verified]
end if
'--print out the result of the verification process
[verified]
if verified = 1 then
html "<div align = 'center'>"
html "<h1>Registration successfull!</h1>"
print "Thanx you for registering."
print "Your account is now verified and active."
html "</div>"
gosub [sendemail]
else
html "<div align = 'center'>"
html "<h1>Verification failed!</h1>"
print "Sorry, but the verification failed."
print "Either you already got verified or your verification-code already expired and/or contains false data."
print "Please try again or sign up again."
html "</div>"
end if
end
'-- send out all the emailstuff
[sendemail]
if verified = 1 then
emailtext$ = emailtext2$
subject$ = subject2$
else
emailtext$ = emailtext$+" "+apppath$+"&"+verifyname$+"="+emailcode$+"&email="+useremail$
end if
smtpsender #aSender, mailserver$
#aSender password(pword$)
#aSender send(fromaddr$, useremail$, subject$, emailtext$)
return
'-- here we gonna start the backend where you can manage the entries and do other stuff
[manage]
if login = 0 then [login]
errorid$ = "manage"
'-- clear all unverfied registrations that are older than X days
cls
html "<h1 align = 'center'>Manage</h1>"
html "<p align = 'center'>"
html "<font color = 'red'>"
print formerror$
formerror$ = ""
html "</font>"
html "</p>"
html "<table align = 'center' border = '1'>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "clear unverfied registrations older than X days : ";
html "</td>"
html "<td>"
textbox #cleardays, 3
button #submit, "Go", [clearunverified]
html "</td>"
html "</tr>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "Show all verified users : ";
html "</td>"
html "<td>"
button #submit, "Go", [showverified]
html "</td>"
html "</tr>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "Send message to verified users : ";
html "</td>"
html "<td>"
button #submit, "Go", [emailusers]
html "</td>"
html "</tr>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "Change settings / admin password : ";
html "</td>"
html "<td>"
button #submit, "Go", [changesettings]
html "</td>"
html "</tr>"
html "</table>"
wait
'-- delete all entries from the DB that are unverified for X days
[clearunverified]
cleardays$ = #cleardays contents$()
if val(cleardays$) < 1 or val(cleardays$) > 100 then
formerror$ = "X has to be a number between 1 and 100"
goto [manage]
end if
userdate = date$("days") ' 36980
userdate = userdate - val(cleardays$)
sqliteconnect #mySQLdb, "register.db"
action$="delete from users where joindate <= (";userdate;") and verified = (";0;");"
#mySQLdb execute(action$)
#mySQLdb execute("vacuum")
#mySQLdb disconnect()
formerror$ = "Done!"
goto [manage]
'-- generate list of all verified users
[showverified]
cls
html "<div align='center'><br />"
button #submit, "Manage", [manage]
sqliteconnect #mySQLdb, "register.db"
query$ = "select user_id, user_name, user_password, user_email from users
where verified = (";1;")
order by user_name asc;"
#mySQLdb execute(query$)
if #mySQLdb HASANSWER() = 0 then
formerror$ = "There are no entries to show."
#mySQLdb disconnect()
goto [manage]
end if
render #mySQLdb
button #submit, "Manage", [manage]
html "</div>"
#mySQLdb disconnect()
wait
'-- create email that can be send to all verified users
[emailusers]
cls
html "<h1 align = 'center'>Send Email</h1>"
html "<p align = 'center'>"
html "<font color = 'red'>"
print formerror$
formerror$ = ""
html "</font>"
html "</p>"
html "<table align = 'center' border = '1'>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "Email subject : "
html "</td>"
html "<td>"
textbox #subject, "" ,62
html "</td>"
html "</tr>"
html "<tr>"
html "<td 'left' valign = 'top'>"
print "Email text : "
html "</td>"
html "<td>"
textarea #text, "" ,50,12
html "</td>"
html "</tr>"
html "<tr>"
html "<td>"
button #submit, "Send", [emailverified]
html "</td>"
html "<td>"
button #submit, "Manage", [manage]
html "</td>"
html "</tr>"
html "</table>"
wait
'-- this actually scans the DB for verified users and sends the email to them
[emailverified]
subject$ = #subject contents$()
emailtext$ = #text contents$()
if subject$ = "" or emailtext$ = "" then
formerror$ = "Please fill in all info!"
goto [emailusers]
end if
sqliteconnect #mySQLdb, "register.db"
query$ = "select user_email from users where verified = (";1;")"
#mySQLdb execute(query$)
while #mySQLdb hasanswer()
useremail$ = #mySQLdb nextrow$()
smtpsender #aSender, mailserver$
#aSender password(pword$)
#aSender send(fromaddr$, useremail$, subject$, emailtext$)
wend
#mySQLdb disconnect()
formerror$ = "Sending messages...... This might take some time...."
goto [emailusers]
[changesettings]
cls
sqliteconnect #mySQLdb, "register.db" ' Connect to the DB
query$ = "SELECT * FROM settings LIMIT 1"
#mySQLdb execute(query$)
result$ = #mySQLdb nextrow$("|")
fields$ = #mySQLdb columnnames$()
#mySQLdb disconnect()
rf = 1
dim a$(14)
dim b$(14)
html "<h1 align = 'center'>Change settings</h1>"
html "<p align = 'center'>"
html "<font color = 'red'>"
print formerror$
formerror$ = ""
html "</font>"
html "</p>"
html "<table align = 'center' border = '1'>"
WHILE word$(fields$,rf,",") <> ""
a$(rf) = trim$(word$(fields$,rf,","))
b$(rf) = trim$(word$(result$,rf,"|"))
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print a$(rf);
print " : ";
html "</td>"
html "<td>"
handle$ = "#chsettings"; rf
textbox #handle$, b$(rf), 50
html "</td>"
html "</tr>"
rf = rf + 1
WEND
html "</table>"
html "<div align = 'center'>"
button #submit, "Apply changes", [writenewsettings]
button #submit, "Manage", [manage]
html "</div>"
wait
[login]
cls
html "<h1 align = 'center'>Login</h1>"
html "<p align = 'center'>"
html "<font color = 'red'>"
print formerror$
formerror$ = ""
html "</font>"
html "</p>"
html "<table align = 'center' border = '1'>"
html "<tr>"
html "<td align = 'left' valign = 'top'>"
print "Enter Password : ";
html "</td>"
html "<td>"
textbox #adminpassword, ""
button #submit, "Submit", [checkadminpassword]
html "</td>"
html "</tr>"
html "</table>"
wait
[checkadminpassword]
if #adminpassword contents$() = adminpassword$ then
login = 1
goto [manage]
else
formerror$ = "Sorry, password is incorrect. Please try again."
goto [login]
end if
[writenewsettings]
sqliteconnect #mySQLdb, "register.db"
query$ = "SELECT * FROM settings LIMIT 1"
#mySQLdb execute(query$)
fields$ = #mySQLdb columnnames$()
#mySQLdb disconnect()
rf = 1
sqliteconnect #mySQLdb, "register.db"
WHILE word$(fields$,rf,",") <> ""
a$ = trim$(word$(fields$,rf,","))
handle$ = "#chsettings"; rf
b$ = #handle$ contents$()
if b$ = "1" or b$ = "0" then
b = val(b$)
action$ = "update settings set '";a$;"' = '";b;"'"
else
action$ = "update settings set '";a$;"' = '";b$;"'"
end if
#mySQLdb execute(action$)
rf = rf + 1
WEND
#mySQLdb disconnect()
formerror$ = "New settings have been applied"
applysettings = 1
goto [readconfig]
'-- here we do some extra errorhandling
[errorhandler]
if errorid$ = "main" then
errorid$ = ""
formerror$ = "Sorry, there was an error. Please try again."
goto [main]
end if
if errorid$ = "manage" then
errorid$ = ""
formerror$ = "Sorry, there was an error. Please try again."
goto [manage]
end if
errorid$ = ""
formerror$ = "Sorry, something unexpected happened. Please start over."
goto [main]
end