Skip to content

Commit

Permalink
solve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
soyapark committed Dec 11, 2020
2 parents 559a2f9 + a614001 commit 01926ab
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 31 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/haystack/murmur?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Django version](https://img.shields.io/badge/django-1.6-blue.svg)](https://docs.djangoproject.com/en/2.2/releases/1.6/) [![python version](https://img.shields.io/badge/python-2.7-yellowgreen.svg)](https://www.python.org/download/releases/2.7/)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/haystack/murmur?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Django version](https://img.shields.io/badge/Django-1.10-blue)](https://docs.djangoproject.com/en/3.0/releases/1.10/) [![python version](https://img.shields.io/badge/python-2.7-yellowgreen.svg)](https://www.python.org/download/releases/2.7/)

Murmur
=
Expand All @@ -10,10 +10,15 @@ Murmur uses Django with a MySQL backend (you can replace with any other backend

Please contact us for an example of the private file. You cannot run the program without it.

#### Install MySQL Server

#### setup the database
* change the root mysql account to one written in private file.
* make sure you can log in to mysql with the password in the command line: `mysql -u root -p`

#### Install Git and clone this repository
* `git clone https://github.com/haystack/murmur.git`

## Running Docker

**Recommended to use Linux**
Expand All @@ -29,7 +34,7 @@ Currently you need a gmail account in order for Murmur to send verification emai
Next set up the environment variables. The only variables you should need to set are your gmail username and password.

1. `cp .env.example .env`
2. Fill in the correct values in `.env` for your gmail account. Make sure to enable insecure logins on gmail.
2. Fill in the correct values in `.env` for your gmail account. Put your gmail address and a google app password.
3. Use `make` to create the database and create a superuser account to login
4. Check it out on `localhost:8000`

Expand All @@ -39,13 +44,6 @@ In order to stop docker you can simply run `make stop` and run `make start` to s

## Not Running Docker i.e. on the server

### Web Installation Instructions

#### Install MySQL Server

#### Install Git and clone this repository
* `git clone https://github.com/haystack/murmur.git`

#### install required linux packages if on linux
* `sudo apt-get install libmysqlclient-dev python-dev`

Expand Down Expand Up @@ -81,7 +79,7 @@ In order to stop docker you can simply run `make stop` and run `make start` to s
#### setup the database
* `mysql -u root -p`
* `create database murmur;`
* Give privileges to the user that will access the database from django: `grant all privileges ON murmur.* TO admin@localhost;`
* Give privileges to the user that will access the database from django: `grant all privileges ON murmur.* TO root@localhost;`

#### install schema and create superuser
* Create new migrations: `python manage.py makemigrations schema`
Expand Down
20 changes: 9 additions & 11 deletions browser/templates/murmur/mobile_list_posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,14 @@ <h4 class="d-inline-block">
<BR><BR>
<input type="text" class="default-text" value="Search within posts" title="Search within posts" />
{% elif not is_member %}
{% if user.is_authenticated %}
<button type="button" id="btn-subscribe-group">Join the list</button>
{% else %}
<a href="/accounts/login/?next=/groups/{{ active_group.name }}">
<button type="button">Join the list</button>
</a>

{% endif %}

<a href="/accounts/register/">Don't have a Murmur account yet?</a>
{% if user.is_authenticated %}
<button type="button" id="btn-subscribe-group">Join the list</button>
{% else %}
<a href="/accounts/login/?next=/groups/{{ active_group.name }}">
<button type="button">Join the list</button>
</a>
<a href="/accounts/register/">Don't have a Murmur account yet?</a>
{% endif %}
{% else %}
<i>You are not in any groups yet. <a href="/group_list">Join or create a new group.</a>
</i>
Expand Down Expand Up @@ -437,4 +435,4 @@ <h4 class="d-inline-block">
});

</script>
{% endblock %}
{% endblock %}
6 changes: 5 additions & 1 deletion browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def error(request):
res['error'] = 'You do not have permission to visit this page.'
elif error == 'thread':
res['error'] = 'This thread no longer exists.'
elif error == 'request_login':
res['error'] = "This group is private. Please log in to view the posts."
else:
res['error'] = 'Unknown error.'
return res
Expand Down Expand Up @@ -162,7 +164,7 @@ def post_list(request):
tag_info = Tag.objects.filter(group=group).annotate(num_p=Count('tagthread')).order_by('-num_p')

if not group.public:
return redirect('/404?e=member')
return redirect('/404?e=request_login')
else:
res = engine.main.list_posts(group_name=request.GET.get('group_name'), format_datetime=False, return_replies=False)
return {'user': request.user, 'groups': groups, 'posts': res, 'active_group': active_group, "tag_info": tag_info}
Expand Down Expand Up @@ -823,6 +825,7 @@ def load_thread(request):
@login_required
def insert_post(request):
try:
logger.debug("insert post")
user = get_object_or_404(UserProfile, email=request.user.email)

group_name = request.POST['group_name']
Expand Down Expand Up @@ -881,6 +884,7 @@ def insert_post(request):
mail.Body = html2text(msg_text) + ps_blurb

relay_mailer.deliver(mail, To = recip.email)
logger.debug("Send email to " + recip.email)

fwding_lists = ForwardingList.objects.filter(group=g, can_receive=True)
for l in fwding_lists:
Expand Down
3 changes: 3 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
# hook django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "http_handler.settings")

import django
django.setup()

# the config/boot.py will turn these values into variables set in settings
4 changes: 2 additions & 2 deletions http_handler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def _get_website():

LOGIN_REDIRECT_URL = "/"


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
DEFAULT_EMAIL = 'no-reply@' + "localhost" if "localhost" in BASE_URL else BASE_URL
DEFAULT_EMAIL = 'no-reply@' + ("localhost" if "localhost" in BASE_URL else BASE_URL)
DEFAULT_FROM_EMAIL = DEFAULT_EMAIL


Expand Down
14 changes: 12 additions & 2 deletions registration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from django.utils.translation import ugettext_lazy as _
from http_handler.settings import WEBSITE
from http_handler.settings import WEBSITE, DEFAULT_FROM_EMAIL
import logging

logger = logging.getLogger('murmur')

class RegistrationForm(forms.Form):
"""
Expand Down Expand Up @@ -111,12 +114,15 @@ class MurmurPasswordResetForm(PasswordResetForm):
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
extra_email_context=None, html_email_template_name="",
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, *args, **kwargs):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
logger.info("reset form")

from django.core.mail import send_mail
UserModel = get_user_model()
email = self.cleaned_data["email"]
Expand Down Expand Up @@ -146,5 +152,9 @@ def save(self, domain_override=None,
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
email = loader.render_to_string(email_template_name, c)
send_mail(subject, email, from_email, [user.email])

from smtp_handler.utils import relay_mailer
from lamson.mail import MailResponse
mail = MailResponse(From = DEFAULT_FROM_EMAIL, To = user.email, Subject = subject, Body = email)
relay_mailer.deliver(mail, To=user.email)

7 changes: 5 additions & 2 deletions schema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from oauth2client.contrib.django_orm import FlowField, CredentialsField

from http_handler import settings
from http_handler.settings import AUTH_USER_MODEL
from http_handler.settings import AUTH_USER_MODEL, DEFAULT_FROM_EMAIL

class Post(models.Model):
id = models.AutoField(primary_key=True)
Expand Down Expand Up @@ -300,7 +300,10 @@ def email_user(self, subject, message, from_email=None):
"""
Sends an email to this User.
"""
send_mail(subject, message, from_email, [self.email])
from smtp_handler.utils import relay_mailer
from lamson.mail import MailResponse
mail = MailResponse(From = DEFAULT_FROM_EMAIL, To = self.email, Subject = subject, Body = message)
relay_mailer.deliver(mail, To=self.email)

def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
Expand Down
4 changes: 2 additions & 2 deletions smtp_handler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def handle_post_squadbox(message, group, host, verified):
def handle_post(message, address=None, host=None):

# restart the db connection
django.db.close_connection()
django.db.close_old_connections()

if '+' in address and '__' in address:
return
Expand Down Expand Up @@ -967,4 +967,4 @@ def send_account_info(message, address=None, host=None):
email_message = email.message_from_string(str(message))
msg_text = get_body(email_message)
mail = MailResponse(From = NO_REPLY, To = message['To'], Subject = message['Subject'], Body = msg_text['plain'])
relay.deliver(mail)
relay.deliver(mail)
2 changes: 1 addition & 1 deletion smtp_handler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
DOWNVOTE_SUFFIX = '__downvote__'
FETCH_SUFFIX = '__fetch__'

ADMIN_EMAILS = ['[email protected]', 'kmahar@mit.edu']
ADMIN_EMAILS = ['soya@mit.edu']

FOLLOW_ADDR = 'http://%s/follow?tid=' % (HOST)
UNFOLLOW_ADDR = 'http://%s/unfollow?tid=' % (HOST)
Expand Down

0 comments on commit 01926ab

Please sign in to comment.