Skip to content

Commit

Permalink
Moved the authentication code to another file
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Jun 28, 2018
1 parent 4566c68 commit 2697406
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 67 deletions.
30 changes: 16 additions & 14 deletions access_point/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ This server can be access on port 5000 when on the same network and `http:10.0.0

## API Endpoints
* /
* This Endpoint returns a basic HTML introductory page
* This Endpoint returns a basic HTML introductory page

* /wifi_credentials/'wifissid'/'wifipassd'
* 'wifissid' is the SSID of the WIFI network you want to configure
* 'wifipassd' is the PASSWORD of that WIFI network
* 'wifissid' is the SSID of the WIFI network you want to configure
* 'wifipassd' is the PASSWORD of that WIFI network

* /config/'stt'/'tts'/'hotword'/'wake'/'auth'/'email'/'passwd'
* 'stt' is the name of Speech To Text Service Provider
- You can choose from 'google', 'ibm', 'bing', 'sphinx'
* 'tts' is the name of Text To Speech Provider
- You can choose from 'google', 'ibm', 'flite'
* 'hotword' is the choice if you want to use Snowboy as the service for hotword prediction
- You can choose from 'y' or 'n'
* 'auth' is the choice if you want to use the speaker in the authenticated mode
- You can choose from 'y' or 'n'
* 'email' is the email of the user
* 'passwd' is the corresponding password
* /config/'stt'/'tts'/'hotword'/'wake'
* 'stt' is the name of Speech To Text Service Provider
- You can choose from 'google', 'ibm', 'bing', 'sphinx'
* 'tts' is the name of Text To Speech Provider
- You can choose from 'google', 'ibm', 'flite'
* 'hotword' is the choice if you want to use Snowboy as the service for hotword prediction
- You can choose from 'y' or 'n'

* /auth/'choice'/'email'/'password'
* 'choice' is the choice if you want to use the speaker in the authenticated mode
- You can choose from 'y' or 'n'
* 'email' is the email of the user
* 'password' is the corresponding password

5 changes: 1 addition & 4 deletions access_point/server/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ STT="$1"
TTS="$2"
HOTWORD="$3"
WAKE="$4"
AUTH="$5"
EMAIL="$6"
PASS="$7"

cd $HOME/SUSI.AI/susi_linux
sudo python3 config_generator.py $STT $TTS $HOTWORD $WAKE $AUTH $EMAIL $PASS
sudo python3 config_generator.py $STT $TTS $HOTWORD $WAKE
7 changes: 7 additions & 0 deletions access_point/server/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash
AUTH="$1"
EMAIL="$2"
PASSWORD="$3"

cd $HOME/SUSI.AI/susi_linux
sudo python3 authentication.py $AUTH $EMAIL $PASSWORD
15 changes: 11 additions & 4 deletions access_point/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ def index():
def install():
return 'starting the installation script'

@app.route('/config/<stt>/<tts>/<hotword>/<wake>/<auth>/<email>/<passwd>')
def config(stt,tts,hotword,wake,auth,email,passwd):
os.system('sudo ./config.sh {} {} {} {} {} {} {}'.format(stt,tts,hotword,wake,auth,email,passwd)) #nosec #pylint-disable type: ignore
@app.route('/config/<stt>/<tts>/<hotword>/<wake>')
def config(stt, tts, hotword, wake):
os.system('sudo ./config.sh {} {} {} {}'.format(stt,tts,hotword,wake)) #nosec #pylint-disable type: ignore
return 'Done' # pylint-enable

@app.route('/auth/<auth>/<email>/<passwd>')
def login(auth, email, passwd):
os.system('sudo ./login.sh {} {} {}'.format(auth, email,passwd)) #nosec #pylint-disable type: ignore
return 'Authenticated' # pylint-enable

@app.route('/wifi_credentials/<wifissid>/<wifipassd>')
def wifi_config(wifissid,wifipassd):
wifi_ssid = wifissid
Expand All @@ -24,4 +29,6 @@ def wifi_config(wifissid,wifipassd):
return 'Wifi Configured' # pylint-enable

if __name__ == '__main__':
app.run(debug=False) # to allow the server to be accessible by any device on the network/access point
app.run(debug=False,host= '0.0.0.0') #nosec #pylint-disable type: ignore
# pylint-enable
# to allow the server to be accessible by any device on the network/access point #pylint-disable type: ignore
38 changes: 38 additions & 0 deletions authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""" Authentication Generator script for Susi Hardware. Run this script and input options
to generate a file for using SUSI in authenticated mode
To run this file use python3 authentication.py <choice_to_be authenticated> <email> <password>
"""
import json_config
import sys

config = json_config.connect('config.json')

def authenticating():
"""Method for setting authentication parameters in the configuration
:return: None
"""
try:
# choice = input('Do you wish to use SUSI in Authenticated Mode? (y/n)\n')
choice = sys.argv[1]
print(choice)
if choice == 'y':
# email = input('Enter SUSI Sign-in Email Address: ')
email = sys.argv[2]
print(email)
# password = input('Enter SUSI Sign-in Password: ')
password = sys.argv[3]
config['usage_mode'] = 'authenticated'
config['login_credentials']['email'] = email
config['login_credentials']['password'] = password
elif choice == 'n':
print('Setting anonymous mode as default')
config['usage_mode'] = 'anonymous'
else:
raise ValueError
except ValueError:
print('Invalid choice. Anonymous mode set as default. Run the configuration script again if you wish '
'to change your choice.')
config['usage_mode'] = 'anonymous'

print("Authenticating \n")
authenticating()
47 changes: 2 additions & 45 deletions config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ def setup_wake_button():
import RPi.GPIO
print("\nDevice supports RPi.GPIO")
# choice = input("Do you wish to enable hardware wake button? (y/n) ")
if sys.argv[6] != 'y':
choice = sys.argv[7]
else:
choice = sys.argv[9]
choice = sys.argv[4]
if choice == 'y':
config['WakeButton'] = 'enabled'
config['Device'] = 'RaspberryPi'
Expand All @@ -60,40 +57,6 @@ def set_extras():
config['detection_bell_sound'] = 'extras/detection-bell.wav'


def request_authentication():
"""Method for setting authentication parameters in the configuration
:return: None
"""
try:
# choice = input('Do you wish to use SUSI in Authenticated Mode? (y/n)\n')
choice = sys.argv[5]
print(choice)
if choice == 'y':
# email = input('Enter SUSI Sign-in Email Address: ')
email = sys.argv[6]
print(email)
# password = input('Enter SUSI Sign-in Password: ')
password = sys.argv[7]
if is_valid(email, password):
print('Login Details are valid. Saving details.')
config['usage_mode'] = 'authenticated'
config['login_credentials']['email'] = email
config['login_credentials']['password'] = password
else:
print('Login Details are invalid. Falling back to Anonymous Mode. Run the configuration script again '
'if you wish to change your choice.')
config['usage_mode'] = 'anonymous'
elif choice == 'n':
print('Setting anonymous mode as default')
config['usage_mode'] = 'anonymous'
else:
raise ValueError
except ValueError:
print('Invalid choice. Anonymous mode set as default. Run the configuration script again if you wish '
'to change your choice.')
config['usage_mode'] = 'anonymous'


def request_hotword_choice():
""" Method to request user for default Hotword Engine and configure it in settings.
"""
Expand Down Expand Up @@ -201,11 +164,8 @@ def request_tts_choice():

# print(len(sys.argv))
if sys.argv[6] != 'y':
if len(sys.argv) != 8:
if len(sys.argv) != 5:
print("Execution style python3 config_generator.py sst tts hotword auth wake")
elif sys.argv[6] == 'n':
if len(sys.argv) != 8:
print("Execution style python3 config_generator.py sst tts hotword auth email password wake")

print("Setup Speech to Text Service\n")
request_stt_choice()
Expand All @@ -219,7 +179,4 @@ def request_tts_choice():
print("Setup Wake Button\n")
setup_wake_button()

print("Setup Authentication to SUSI.AI\n")
request_authentication()

print("Run SUSI by 'python3 -m main'")

0 comments on commit 2697406

Please sign in to comment.