summaryrefslogtreecommitdiff
path: root/tools/mmd/MmdCommands.py
blob: 2b5db420e3a59aa983dc12f8b2e5ad33cd117aa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"""
command methods for MURSAT1 Mission Dashboard
"""

from cgi import parse_qs, escape
from mmd.MmdWidgets import *
from mmd.MmdUser import User

def loginForm (session):
  """
  display the login form
  """
  return indexWidget (menuWidget (session), loginFormWidget (), statusWidget (session), session)

def login (session):
  """
  evaluate data from loginForm
  """
  if not session.user.load (session.getQsEmail ()):
    session.message = 'Login failed (E013).'
    return indexWidget (menuWidget (session), osmWidget (session), statusWidget (session), session)
  if not session.user.checkPassword (session.getQsPassword ()):
    session.message = 'Login failed (E113).'
    return indexWidget (menuWidget (session), osmWidget (session), statusWidget (session), session)
  session.setStatus ('auth')
  session.message = 'Welcome {0} {1}!'.format (session.user.firstname, session.user.lastname)
  return indexWidget (menuWidget (session), osmWidget (session), statusWidget (session), session)

def logout (session):
  session.user.email = 'Anonymous'
  session.setStatus ()
  session.message = 'You have logged out successfully.'
  return indexWidget (menuWidget (session), osmWidget (session), statusWidget (session), session)

def registerForm (session):
  """
  display the register form
  """
  return indexWidget (menuWidget (session), registerFormWidget (), statusWidget (session), session)

def register (session):
  """
  evaluate data from registerForm
  """
  firstname = session.getQsFirstname ()
  lastname = session.getQsLastname ()
  email = session.getQsEmail ()
  callsign = session.getQsCallsign ()
  longitude = session.getQsLongitude ()
  latitude = session.getQsLatitude ()
  location_name = session.getQsLocationName ()
  password = session.getQsPassword ()
  confirm = session.getQsConfirm ()
  altitude = session.getQsAltitude ()

  if password != confirm:
    error_message = {'error': 'Password', 'description': 'Passwords do not match.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)

  user = User ()
  code = user.create (session.session_id, firstname, lastname, email, callsign, password)

  if not code:
    error_message = {'error': 'Register', 'description': 'Registration failed.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)

  if longitude != '' and latitude != '' and location_name != '':
    user.addLocation (location_name, longitude, latitude, altitude, 'yes')

  message = '''From: noreply <noreply@mur.at>
To: "{0} {1}" <{2}>
Subject: MMD registration confirmation request

Dear {0} {1},

someone (probably you) has registered at the MURSAT1 Mission Dashbaord
(MMD) at http://sat.mur.at/dashboard.  Please confirm the registration
using the link below:


  http://hofos.at/mmd/?cmd=completeRegistration&code={3}

Regards,
MURSAT1 team
'''.format (user.firstname, user.lastname, user.email, code)

  if not user.sendEmail (message):
    error_message = {'error': 'Email', 'description': 'Email could not be sent.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)

  return indexWidget (menuWidget (session), registerWidget (), statusWidget (session), session)

def completeRegistration (session):
  code = session.getQsCode ()
  if not session.user.findPending (code):
    error_message = {'error': 'Registration', 'description': 'Registration Failed.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)
  return indexWidget (menuWidget (session), completeRegistrationWidget (code), statusWidget (session), session)

def confirmRegistration (session):
  code = session.getQsCode ()
  if not session.user.findPending (code):
    error_message = {'error': 'Registration', 'description': 'Registration Failed.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)
  session.user.confirm (code)
  session.setStatus ('auth')
  return indexWidget (menuWidget (session), confirmRegistrationWidget (session.user), statusWidget (session), session)

def cancelRegistration (session):
  code = session.getQsCode ()
  if not session.user.findPending (code):
    error_message = {'error': 'Registration', 'description': 'Canceling failed.'}
    return indexWidget (menuWidget (session), errorWidget (error_message), statusWidget (session), session)
  session.user.cancel (code)
  return indexWidget (menuWidget (session), cancelRegistrationWidget (), statusWidget (session), session)

def mmdCredits (session):
  '''
  display a page with credits/thanks
  '''
  return indexWidget (menuWidget (session), creditsWidget (), statusWidget (session))

def submitForm (session):
  """
  display the form for data submission
  """
  return indexWidget (menuWidget (session), submitFormWidget (), statusWidget (session), session)

def submit (session):
  """
  evaluate data from submitForm
  """
  return indexWidget (menuWidget (session), submitWidget (), statusWidget (session), session)

def viewlog (session):
  """
  show latest log entries/submissions
  """
  return indexWidget (menuWidget (session), logWidget (), statusWidget (session), session)

def index (session):
  """
  display the index page
  """
  satellite = {'longitude': 15.4426, 'latitude': 47.06576}
  return indexWidget (menuWidget (session), osmWidget (session), statusWidget (session), session)

def mmdtest (env, cookie):
  body = ''
  for key, value in sorted (env.items()):
    body = '{0}{1}: {2}\n'.format (body, key, value)
  body = '{0}Cookie: {1}\n'.format (body, cookie['mmd'].value)
  return body

if __name__ == "__main__":
  pass

# vim: tw=0 ts=2 expandtab
# EOF