예제 #1
0
def sign_up_in(request):
	post = request.GET
	email = post['email']
	password = post['password']
	firstName = post['firstName']
	lastName = post['lastName']
	if not user_exists(email):
		user = create_user(username=email, email=email, password=password)
		user.first_name = firstName
		user.last_name = lastName
		
		user.save()
		approval = Pending()
		approval.user = user
		approval.approved = False
		approval.save()
		data = {}
		data['response'] = 'Your request has been submitted for approval by admin.'
		response = HttpResponse(json.dumps(data), content_type = "application/json")
		response.status_code = 201
		return response
	else:
		data = {}
		data['response'] = 'Error: User already exists'
		response = HttpResponse(json.dumps(data), content_type = "application/json")
		response.status_code = 403
		return response
예제 #2
0
파일: views.py 프로젝트: issfangks/milo-lab
def upload_sigma_pdf(request):
    if request.method == 'POST':
        form = UploadSigmaPdfForm(request.POST, request.FILES)
        if form.is_valid():
            pending_list = []
            for primer in pdfMine(request.FILES['file']):
                entry = Pending(name=primer[0], seq=primer[1])
                entry.save()
                pending_list.append(entry)
            return render_to_response('upload_success.html',
                                      {'primers_list': pending_list})
        else:
            return error("Invalid operation")
    else:
        form = UploadSigmaPdfForm()
    return render_to_response('upload.html', {'form': form})
예제 #3
0
def upload_sigma_pdf(request):
    if request.method == 'POST':
        form = UploadSigmaPdfForm(request.POST, request.FILES)
        if form.is_valid():
            pending_list = []
            for primer in pdfMine(request.FILES['file']):
                entry = Pending(name=primer[0], seq=primer[1])
                entry.save()
                pending_list.append(entry)
            return render_to_response('upload_success.html',
                                      {'primers_list': pending_list})
        else:
            return error("Invalid operation")
    else:
        form = UploadSigmaPdfForm()
    return render_to_response('upload.html', {'form': form})
예제 #4
0
파일: views.py 프로젝트: issfangks/milo-lab
def fetch_mail(request):
    fetch_form = FetchMailForm(request.POST)
    
    if not fetch_form.is_valid():
        return Http404
    
    user = fetch_form.cleaned_data["email"]
    pwd = fetch_form.cleaned_data["password"]
    
    # connecting to the gmail imap server
    imap = imaplib.IMAP4_SSL("imap.gmail.com")
    resp, _items = imap.login(user, pwd)
    if resp != 'OK':
        return error("Wrong user name or password")
       
    #m.select("[Gmail]/INBOX") # here you a can choose a mail box like INBOX instead
    resp, _items = imap.select('sigma')
    if resp != 'OK':
        return error("Cannot locate label 'sigma'")
    
    resp, items = imap.search(None, '(SUBJECT "Sigma-Aldrich Order confirmation")')
    if resp != 'OK':
        return error("Cannot search for emails for Sigma")
    items = items[0].split() # getting the mails id
    
    pending_list = []
    for emailid in items:
        # fetching the mail, "`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
        resp, data = imap.fetch(emailid, "(RFC822)")
        if data is None or data[0] is None:
            continue
        email_body = data[0][1] # getting the mail content
        mail = email.message_from_string(email_body) # parsing the mail content to get a mail object
    
        # Check if any attachments at all
        if mail.get_content_maintype() != 'multipart':
            continue
    
        print "["+mail["From"]+"] :" + mail["Subject"]
    
        # we use walk to create a generator so we can iterate on the parts and forget about the recursive headach
        for part in mail.walk():
            # multipart are just containers, so we skip them
            if part.get_content_maintype() == 'multipart':
                continue
    
            # is this part an attachment ?
            if part.get('Content-Disposition') is None:
                continue
    
            # finally write the stuff
            fp = io.BytesIO()
            fp.write(part.get_payload(decode=True))
            fp.seek(0)
            #apply_lbl_msg = imap.uid('COPY', emailid, 'done')
            #if apply_lbl_msg[0] == 'OK':
            #    mov, data = imap.uid('STORE', emailid , '+FLAGS', '(\Deleted)')
            #    imap.expunge()                
            try:
                for primer in pdfMine(fp):
                    entry = Pending(name=primer[0], seq=primer[1])
                    entry.save()
                    pending_list.append(entry)
            except PDFSyntaxError:
                pass
            fp.close()

    return render_to_response('upload_success.html',
                                      {'primers_list': pending_list})
예제 #5
0
def fetch_mail(request):
    fetch_form = FetchMailForm(request.POST)

    if not fetch_form.is_valid():
        return Http404

    user = fetch_form.cleaned_data["email"]
    pwd = fetch_form.cleaned_data["password"]

    # connecting to the gmail imap server
    imap = imaplib.IMAP4_SSL("imap.gmail.com")
    resp, _items = imap.login(user, pwd)
    if resp != 'OK':
        return error("Wrong user name or password")

    #m.select("[Gmail]/INBOX") # here you a can choose a mail box like INBOX instead
    resp, _items = imap.select('sigma')
    if resp != 'OK':
        return error("Cannot locate label 'sigma'")

    resp, items = imap.search(None,
                              '(SUBJECT "Sigma-Aldrich Order confirmation")')
    if resp != 'OK':
        return error("Cannot search for emails for Sigma")
    items = items[0].split()  # getting the mails id

    pending_list = []
    for emailid in items:
        # fetching the mail, "`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
        resp, data = imap.fetch(emailid, "(RFC822)")
        if data is None or data[0] is None:
            continue
        email_body = data[0][1]  # getting the mail content
        mail = email.message_from_string(
            email_body)  # parsing the mail content to get a mail object

        # Check if any attachments at all
        if mail.get_content_maintype() != 'multipart':
            continue

        print "[" + mail["From"] + "] :" + mail["Subject"]

        # we use walk to create a generator so we can iterate on the parts and forget about the recursive headach
        for part in mail.walk():
            # multipart are just containers, so we skip them
            if part.get_content_maintype() == 'multipart':
                continue

            # is this part an attachment ?
            if part.get('Content-Disposition') is None:
                continue

            # finally write the stuff
            fp = io.BytesIO()
            fp.write(part.get_payload(decode=True))
            fp.seek(0)
            #apply_lbl_msg = imap.uid('COPY', emailid, 'done')
            #if apply_lbl_msg[0] == 'OK':
            #    mov, data = imap.uid('STORE', emailid , '+FLAGS', '(\Deleted)')
            #    imap.expunge()
            try:
                for primer in pdfMine(fp):
                    entry = Pending(name=primer[0], seq=primer[1])
                    entry.save()
                    pending_list.append(entry)
            except PDFSyntaxError:
                pass
            fp.close()

    return render_to_response('upload_success.html',
                              {'primers_list': pending_list})