Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some APIs and fixed some bugs #86

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 163 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,129 @@
## API Endpoints
A description of all the API endpoints, their URL and request parameters.
### Users
#### View User

#### Login
```
url : /users/auth/login/
method : POST
parameters = {
"username" : "<username>",
"password" : "<password>:
}
```
```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```
#### Logout
```
url : /users/auth/logout/
method : POST
parameters = {}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED
```
#### Update FB link
```
url : /users/updatefb/
method : POST
parameters = {"fblink" : "<Your fb link>"}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED / 400_BAD_REQUEST

Note : User needs to be logged in to use this API
```
#### Forgot Password Mailer
```
url : /users/forgotpassemail/
method : POST
parameters = { "roll" : "<Your IITK roll no>"}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED / 400_BAD_REQUEST

Note: If successful, it sends a link at the users e-mail id which is described below.
```
#### Forgot Password
```
url : /users/forgotpass/code=<str:token>/
method : POST
parameters = {}
```
```
Successful :{
status : 200_OK
message : Account successfully deactivated. Now follow activation process to create new password and activate account.
}
Unsuccessful : {
status : 401_UNAUTHORIZED
message : "Token already used" or "Invalid token or invalid request"
}

```
#### Reset Password Mailer
```
url : /users/resetpassemail/
method : POST
parameters = {"roll" : "<Your IITK roll>"}
```
```
Successful : 202_ACCEPTED
Unsuccessful : 403_FORBIDDEN / 400_BAD_REQUEST

Note : User needs to be logged in to use this API. This sends an e-mail to reset password.
```
#### Reset Password
```
url : /users/resetpass/code=<str:token>/
method : POST
parameters = {
"new_password1" : "<Your new password>" ,
"new_password2" : "<Your new password again>",
"old_password" : "<Your new password>"
}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED

Note : User needs to be logged in to use this API.
```

#### Registration Mailer
```
url : /users/register/
method : POST
parameters = {
"roll" : "<Your IITK roll>"
}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED

Note : This sends an activation mail to the user.
```
#### Registration and set password
```
url : /users/register/verify/code=<str:token>/
method : POST
parameters = {
"password" : "<Your password>"
}
```
```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED

```

#### View User's Profile
```
url : /users/profile/
method : GET
Expand All @@ -20,29 +142,48 @@ Response : {

Note : User needs to be logged in to use this API.
```
#### Login
#### View Other's Profile(by name)
```
url : /users/auth/login/
url : /users/peoplename/
method : POST
parameters = {
"username" : "<username>",
"password" : "<password>:
}
```
```
"username"
}
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
Unsuccessful : 404_BAD_REQUEST / 401_UNAUTHORIZED

Response : {
"roll",
"username",
"name",
"email",
"fblink"
}

Note : User needs to be logged in to use this API.
```
#### Logout
#### View Other's Profile(by roll)
```
url : /users/auth/logout/
url : /users/peopleroll/
method : POST
parameters = {}
```
```
parameters = {
"roll"
}
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED
Unsuccessful : 404_BAD_REQUEST / 401_UNAUTHORIZED

Response : {
"roll",
"username",
"name",
"email",
"fblink"
}

Note : User needs to be logged in to use this API.
```


#### Follow User
To follow another user.
```
Expand All @@ -58,7 +199,7 @@ Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
To unfollow a user who is already followed.
```
url : /users/unfollow/
method : DELETE
method : POST
parameters = {"username" : "<username of the user to be unfollowed">}
```
```
Expand Down Expand Up @@ -143,7 +284,7 @@ Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
Allows deletion of a post by its author.
```
url : /posts/delete/
method : DELETE
method : POST
parameters = {"pk" : "<primary key of the post>"}
```
```
Expand Down Expand Up @@ -189,7 +330,7 @@ To follow a stream.
```
url : /streams/follow/
method : PUT
parameters = {"title" : "<title of the stream to be followed>"}
parameters = {"pk" : "<pk of the stream to be followed>"}
```
```
Successful : 200_OK
Expand All @@ -199,8 +340,8 @@ Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
To unfollow a stream.
```
url : /streams/unfollow/
method : DELETE
parameters = {"title" : "<title of the stream to be unfollowed>"}
method : POST
parameters = {"pk" : "<pk of the stream to be unfollowed>"}
```
```
Successful : 200_OK
Expand Down Expand Up @@ -304,7 +445,7 @@ Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED / 404_NOT_FOUND
To delete a comment on a post(all sub-comments will be deleted)/delete sub-comments(all of its sub-comments will be deleted).Recursive deletion will be followed
```
url : /comments/delete
method : DELETE
method : POST
parameters = {
"pk":"<primary key of the comment>"
}
Expand Down Expand Up @@ -336,4 +477,4 @@ Successful : [
},
]
Unsuccessful : 404_NOT_FOUND
```
```
2 changes: 1 addition & 1 deletion bookmark/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def post(self,request):
pk = request.data['pk']
try:
post = Post.objects.get(pk=pk)
except post.DoesNotExist:
except Post.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
user = IsLoggedIn(request)
if user is None:
Expand Down
26 changes: 19 additions & 7 deletions campusdiscussbackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def get_secret(setting, secrets=secrets):
'bookmark.apps.BookmarkConfig',
'tokens.apps.TokensConfig',
'rest_framework',
'corsheaders',
]

REST_FRAMEWORK = {
Expand All @@ -71,14 +72,22 @@ def get_secret(setting, secrets=secrets):
CSRF_COOKIE_SECURE = True

MIDDLEWARE = [

'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

]
CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_WHITELIST = (
'http://localhost:3001',
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this done to solve the cors issue with the frontend? If that was only the purpose, then remove this.


ROOT_URLCONF = 'campusdiscussbackend.urls'

Expand All @@ -105,15 +114,17 @@ def get_secret(setting, secrets=secrets):
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "postgres",
"USER": "vikrant",
"PASSWORD": get_secret("DB_PASSWORD"),
'HOST': 'localhost',
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'password',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the password field back to the previous manner.

'HOST': '127.0.0.1',
'PORT': '5432',
}
}

#EXPO_SERVER="http://127.0.0.1:8080/"
EXPO_SERVER="https://server.com"

# Password validation
Expand Down Expand Up @@ -162,5 +173,6 @@ def get_secret(setting, secrets=secrets):
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
DEFAULT_AUTO_FIELD='django.db.models.AutoField'


#APPEND_SLASH=False
11 changes: 9 additions & 2 deletions campusdiscussbackend/settings_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mmtp.iitk.ac.in'
EMAIL_HOST = 'smtp.gmail.com'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please configure it back to iitk webmail configurations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

EMAIL_USE_TLS = True
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
Expand All @@ -12,6 +12,7 @@
EMAIL_SUBJECT = {
"Activation": "Activation mail for Campus Discuss",
"PasswordReset": "Password Reset Email For Campus Discuss",
"ForgotPass" : "Forgot Password mail for Campus Discuss"
}
EMAIL_BODY = {
"Activation": """Hi {name:s}!
Expand All @@ -20,12 +21,18 @@
"PasswordReset": """Hi {name:s}!
Click on the followiing link or copy-paste it to continue with the password reset procedure.
{link:s}.""",
"ForgotPass" : """Hi {name:s}!
Click on the following link or copy-paste it to continue with setting new password for your account.
{link:s}"""
}
REDIRECT_LINK = {
"Activation": "http://127.0.0.1:8000/",
"PasswordReset": "/",
"ForgotPass" : "/"
}
EMAIL_LINK = {
"Activation":"http://127.0.0.1:8000/users/verify/code={code:s}/",
"Activation":"http://127.0.0.1:8000/users/register/verify/code={code:s}/",
"PasswordReset": "http://127.0.0.1:8000/users/resetpass/code={code:s}/",
"ForgotPass" : "http://127.0.0.1:8000/users/forgotpass/code={code:s}/",
}

4 changes: 2 additions & 2 deletions comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def post(self,request):
content = request.data['content']
try:
post = Post.objects.get(pk=post_id)
except post.DoesNotExist:
except Post.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
try:
parent_id = request.data['parent_id']
Expand Down Expand Up @@ -46,7 +46,7 @@ def recursiveDelete(comment):

class DeleteComment(APIView):

def delete(self, request):
def post(self, request):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a delete request instead of a post request because you are deleting the comments.

try:
user = IsLoggedIn(request)
if user is None:
Expand Down
2 changes: 1 addition & 1 deletion posts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def post(self, request):

class DeletePostView(APIView):

def delete(self, request):
def post(self, request):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here also.

user = IsLoggedIn(request)
if user is not None:
try:
Expand Down
Loading