From 6fffac66c0faa119dbfeda5b07069fe0811b8f02 Mon Sep 17 00:00:00 2001 From: IssaIan Date: Mon, 10 Dec 2018 13:07:33 +0300 Subject: [PATCH 1/3] [finish-#-162538530]Create uder login --- commandblog.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 commandblog.py diff --git a/commandblog.py b/commandblog.py new file mode 100644 index 0000000..b58a6c6 --- /dev/null +++ b/commandblog.py @@ -0,0 +1,43 @@ +comments = [] +users = [ + { + "name": "kenn", + "password": "1234", + "role": "admin" + }, + { + "name": "issa", + "password": "1234", + "role": "moderator" + }, + { + "name": "eric", + "password": "1234", + "role": "normal" + }, + { + "name": "steve", + "password": "1234", + "role": "normal" + } +] + + +class MyClass: + def __init__(self): + self.user = users + + def login(self): + x = input("Enter your name.") + for user in users: + if user['name'] == x: + return user['password'] + y = input('Enter your password: ') + if user['password'] == y: + print('You are now logged in!') + else: + print('wrong password!') + break + +myclass = MyClass() +myclass.login() From 8e9d8e3ea02480acd7ccda837581a9727ba89b16 Mon Sep 17 00:00:00 2001 From: IssaIan Date: Mon, 10 Dec 2018 13:59:22 +0300 Subject: [PATCH 2/3] [finish-#-162538615]Create user comment --- commandblog.py | 62 +++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/commandblog.py b/commandblog.py index b58a6c6..96fe7c7 100644 --- a/commandblog.py +++ b/commandblog.py @@ -1,20 +1,26 @@ +import datetime + comments = [] users = [ { "name": "kenn", "password": "1234", - "role": "admin" + "role": "admin", + "lastLoginAt": "" + }, { "name": "issa", "password": "1234", - "role": "moderator" - }, + "role": "moderator", + "lastLoginAt": "" + }, { "name": "eric", "password": "1234", - "role": "normal" - }, + "role": "normal", + "lastLoginAt": "" + }, { "name": "steve", "password": "1234", @@ -22,22 +28,32 @@ } ] +def login(): + username = input("please input username: ") + + for user in users: + if user['name'] == username: + # return user['password'] + password = input("please input password: ") + if user['password'] != password: + print('Wrong password') + user["lastLoginAt"] = datetime.datetime.now() + + if user['role'] == "normal": + userinput = input("1. create comment \n 2.Edit comment \n 3. logout ") + + if userinput == str("1"): + comment = input("Enter your comment:") + + data = {'comment_id': len(comments) +1, + 'comment': comment, + 'timestamp': datetime.datetime.now() , + 'created_by': username + } + comments.append(data) + return comments + + + -class MyClass: - def __init__(self): - self.user = users - - def login(self): - x = input("Enter your name.") - for user in users: - if user['name'] == x: - return user['password'] - y = input('Enter your password: ') - if user['password'] == y: - print('You are now logged in!') - else: - print('wrong password!') - break - -myclass = MyClass() -myclass.login() +print(login()) \ No newline at end of file From a02d16d31eacdb50f62789e5cbf1321faefacb11 Mon Sep 17 00:00:00 2001 From: IssaIan Date: Mon, 10 Dec 2018 15:08:42 +0300 Subject: [PATCH 3/3] [starts #162539042]Add moderator user edit comment --- commandblog.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/commandblog.py b/commandblog.py index 96fe7c7..6daa24f 100644 --- a/commandblog.py +++ b/commandblog.py @@ -36,7 +36,7 @@ def login(): # return user['password'] password = input("please input password: ") if user['password'] != password: - print('Wrong password') + return 'Wrong password' user["lastLoginAt"] = datetime.datetime.now() if user['role'] == "normal": @@ -45,15 +45,70 @@ def login(): if userinput == str("1"): comment = input("Enter your comment:") - data = {'comment_id': len(comments) +1, + data = {'comment_id': len(comments) +1, 'comment': comment, 'timestamp': datetime.datetime.now() , 'created_by': username } - comments.append(data) - return comments + comments.append(data) + return comments + elif userinput == str("2"): + comment_id = int(input('Enter comment id:')) + if not comment_id: + return "Enter comment id" + comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + if comment == False: + return "No comment found" + edit = input("Enter your comment here:") + comment["comment"] = edit + return comments + + else: + login() + + + if user['role'] == "moderator": + userinput = input("1. create comment \n 2. edit comment \n 3. delete comment \n 4. logout \n ") + + if userinput == str("1"): + comment = input("Enter your comment:") + data = {'comment_id': len(comments) +1, + 'comment': comment, + 'timestamp': datetime.datetime.now() , + 'created_by': username + } + comments.append(data) + return comments + + elif userinput == str("2"): + comment_id = int(input('Enter comment id:')) + if not comment_id: + return "Enter comment id: " + comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + if comment == False: + return "No comment found" + edit = input("Enter your comment here:") + comment["comment"] = edit + return comments + elif userinput == str("3"): + comment_id = int(input('Enter comment id')) + if not comment_id: + return 'Enter comment id' + comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False) + if comment == False: + return "No comment found" + comments.remove(comment) + return comments + + + else: + login() + + + + print(login()) \ No newline at end of file