hopefully it works
This commit is contained in:
parent
66d0d3858b
commit
98847ffc51
42
sentry.rb
42
sentry.rb
|
@ -2,6 +2,9 @@ require_relative 'hyde/hyde'
|
|||
require 'xmpp4r'
|
||||
require 'net/smtp'
|
||||
require 'json'
|
||||
require 'uri'
|
||||
|
||||
norxondor_gorgonax = URI::MailTo::EMAIL_REGEXP
|
||||
|
||||
CONFIG = JSON.load_file(Dir.pwd+"/.config.json")
|
||||
|
||||
|
@ -13,16 +16,23 @@ SMTP_PASS = CONFIG["pass"]
|
|||
SMTP_TLS = CONFIG["tls"]
|
||||
SMTP_STARTTLS = CONFIG["starttls"]
|
||||
SMTP_AUTH = CONFIG["auth"].to_sym
|
||||
JABBER_SERVER = CONFIG["jabber-server"]
|
||||
HTTP_SERVER_ROOT = CONFIG['http-server-root']
|
||||
|
||||
Pending = {}
|
||||
Pending_by_username = {}
|
||||
|
||||
def myroot(req)
|
||||
if req.ssl? then
|
||||
return "https://#{req.host}:#{req.port}"
|
||||
return "https://#{HTTP_SERVER_ROOT}"
|
||||
else
|
||||
return "http://#{req.host}:#{req.port}"
|
||||
return "http://#{HTTP_SERVER_ROOT}"
|
||||
end
|
||||
end
|
||||
|
||||
def register(username,password)
|
||||
cl = Jabber::Client.new(Jabber::JID.new(
|
||||
|
||||
def sendmail(code,email)
|
||||
smtp = Net::SMTP.new(SMTP_SERVER, SMTP_PORT)
|
||||
msg_headers = ''
|
||||
|
@ -49,19 +59,26 @@ server = Hyde::Server.new Port: 8001 do
|
|||
end
|
||||
path "api" do
|
||||
post 'register' do |ctx|
|
||||
server_uri = myroot ctx.request
|
||||
# Add pending user
|
||||
key = (1..32).map { |x| "0123456789ABCDEF"[(rand()*15).round] }.join
|
||||
user = ctx.request.query['user']
|
||||
password = ctx.request.query['password']
|
||||
email = ctx.request.query['email']
|
||||
expires_on = Time.now+60*60*2
|
||||
Pending[key] = {
|
||||
unless user.match /^[\w_-]+$/ and
|
||||
email.match norxondor_gorgonax and
|
||||
password.match /^.{8,}$/ then
|
||||
redirect server_uri+"/register/error.html"
|
||||
end
|
||||
if Pending_by_username[user] then
|
||||
redirect server_uri+"/register/error.html"
|
||||
end
|
||||
Pending_by_username[user] = Pending[key] = {
|
||||
"user" => user,
|
||||
"password" => password,
|
||||
"email" => email,
|
||||
"expires_one" => expires_on
|
||||
"expires_on" => expires_on
|
||||
}
|
||||
server_uri = myroot ctx.request
|
||||
begin
|
||||
sendmail(key,email)
|
||||
redirect server_uri+"/register/validate.html"
|
||||
|
@ -73,11 +90,18 @@ server = Hyde::Server.new Port: 8001 do
|
|||
server_uri = myroot ctx.request
|
||||
key = ctx.request.query['key']
|
||||
if Pending.has_key? key then
|
||||
# do things here
|
||||
puts Pending[key], "successfully verified"
|
||||
if Pending[key].expires_on < Time.now then
|
||||
puts "#{Pending.delete key} expired"
|
||||
redirect server_uri+"/register/error.html"
|
||||
end
|
||||
cl = Jabber::Client.new(Jabber::JID.new(Pending[key]["user"]+"@"+JABBER_SERVER))
|
||||
cl.connect
|
||||
cl.register(Pending[key]["password"])
|
||||
cl.close
|
||||
puts "#{Pending[key]} successfully verified"
|
||||
redirect server_uri+"/register/success.html"
|
||||
else
|
||||
puts Pending[key], "failed to verify"
|
||||
puts "#{Pending[key]} failed to verify"
|
||||
redirect server_uri+"/register/error.html"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
<button>Register</button>
|
||||
</div>
|
||||
</form>
|
||||
<p> Requirements: </p>
|
||||
<ul>
|
||||
<li> Valid email (only for verification) </li>
|
||||
<li> A password that is at least 8 characters long </li>
|
||||
<li> A username that contains slashes, dashes, and alphanumeric characters</li>
|
||||
</ul>
|
||||
<p> Review the source code of this <a href="https://adastra7.net/git/Yessiest/sentry">registration page</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
Loading…
Reference in New Issue