Thursday, October 18, 2018

facebook twitter widget on sidebar

<div id="tabs" class="col-sm-9 social-tab-control">
                <div class="col-sm-12">
                    <ul class="social-tab">
                        <li class="facebook">
                            <a href="#facebook-tab"><i class="fa fa-facebook"></i> Facebook</a>
                        </li>
                        <li class="twitter">
                            <a href="#twitter-tab"><i class="fa fa-twitter"></i> Twitter</a>
                        </li>
                    </ul>
                </div>
                <div class="col-sm-12">
                    <div id="facebook-tab">

                        <div class="social-item-wrap">
                            <?php for ($i = 0; $i < 0; $i++): ?>
                                <div class="social-item">
                                    <h5>5 ЦАГИЙН ӨМНӨ</h5>
                                    <a href="#" class="social-link">@suisfacebooklink</a>
                                    <span>СУИС-ийн “Оюутан” театрын тайзнаа тоглох энэ удаагийн “Учиртай гурван толгой” дуурийн Ерөнхий найруулагчаар МУАЖ А.Долгор, удирдаачаар ....</span>
                                </div>
                            <?php endfor; ?>
                        </div>

                    </div>

                    <div id="twitter-tab">

                        <div class="social-item-wrap">

                            <a class="twitter-timeline" data-chrome="nofooter noborders" data-dnt="true" href="https://twitter.com/MSUAC" data-widget-id="637864063012311041">Tweets by @MSUAC</a>
                            <script>!function (d, s, id) {
                                    var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
                                    if (!d.getElementById(id)) {
                                        js = d.createElement(s);
                                        js.id = id;
                                        js.src = p + "://platform.twitter.com/widgets.js";
                                        fjs.parentNode.insertBefore(js, fjs);
                                    }
                                }(document, "script", "twitter-wjs");</script>


                        </div>
                    </div>
                </div>

            </div>

Wednesday, August 15, 2018

nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  api.odo.mn seller.odo.mn supply.odo.mn admin.odo.mn order.odo.mn odo.mn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

location / {
proxy_pass http://0.0.0.0:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
    }

server {
listen 80;
server_name login.odo.mn;
location / {
proxy_pass http://0.0.0.0:8002;
proxy_set_header Host login.odo.mn;
}
}


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Tuesday, July 3, 2018

python your oauth server login using google account integration

from flask import flash, redirect, url_for, session, request, jsonify
from flask_oauthlib.client import OAuth
from app.models.company_models import Company, CompanyInfo, Branch
from app.models.shared_models import Sphere, Business
from app import instance, oauth as my_oauth, my_mail
from app.models.auth_models import User
from flask_login import login_user, logout_user, current_user, login_required
import urllib
from app.helpers.url_helper import base_url
from app.libraries.odo.odo_common import uuid_generator

GOOGLE_CLIENT_ID = '1059700860469-sdfaasdf.apps.googleusercontent.com'
GOOGLE_CLIENT_SECRET = 'asdf'
# one of the Redirect URIs from Google APIs console
AUTH_REDIRECT_URI = '/googleauth/callback'

google_oauth = OAuth(instance)

google = google_oauth.remote_app(
'google',
consumer_key=GOOGLE_CLIENT_ID,
consumer_secret=GOOGLE_CLIENT_SECRET,
request_token_params={
'scope': 'email'
},
base_url='https://www.googleapis.com/oauth2/v1/',
request_token_url=None,
access_token_method='POST',
access_token_url='https://accounts.google.com/o/oauth2/token',
authorize_url='https://accounts.google.com/o/oauth2/auth',
)


@instance.route('/googleauth', methods=['GET', 'POST'])
def googleauth_index():
return redirect(url_for('googleauth_login', **request.args))


@instance.route('/googleauth/login')
def googleauth_login():
session['x_response_type'] = request.args['response_type']
session['x_client_id'] = request.args['client_id']
session['x_redirect_uri'] = request.args['redirect_uri']
session['x_scope'] = request.args['scope']

if 'google_token' in session:
token = session['google_token']
if not token is None:
googleauth_revoke()
session.pop('google_token')

return google.authorize(callback=url_for('googleauth_authorized', _external=True))


@instance.route('/googleauth/logout')
def googleauth_logout():

if 'google_token' in session:
token = session['google_token']
if token:
googleauth_revoke()
session.pop('google_token')

return redirect(base_url('order'))


@instance.route(AUTH_REDIRECT_URI)
def googleauth_authorized():

resp = google.authorized_response()

# try to revoke
if resp is None:
return 'Access denied: reason=%s error=%s' % (
request.args['error_reason'],
request.args['error_description']
)

session['google_token'] = (resp['access_token'], '')
google_user = google.get('userinfo').data
user = User.query.filter_by(email=google_user['email']).first()

if not user:
new_password = uuid_generator()

user = User()
user.username = google_user['email']
user.email = google_user['email']
user.password = new_password
user.role_id = 6 # new user is admin for your self
try:
user.save()

body = "Google хэрэглэгчээр системд бүртгүүлсэн нууц үг: " + new_password + ""
my_mail.Send("Таны систем дээрх нууц үг", body, [user.email])
except Exception as e:
flash('Хэрэглэгч бүртгэхэд алдаа гарлаа! ' +
str(e), category='error')

if login_user(user):
response_type = session['x_response_type']
client_id = session['x_client_id']
redirect_uri = session['x_redirect_uri']
scope = session['x_scope']
return redirect(url_for('googleauth_confirm_authorization', response_type=response_type, client_id=client_id, redirect_uri=redirect_uri, scope=scope))


@instance.route('/googleauth/confirm', methods=['GET', 'POST'])
@login_required
def googleauth_confirm_authorization():
return my_oauth.confirm_authorization_request()


@google.tokengetter
def googleauth_get_google_oauth_token():
return session.get('google_token')


def googleauth_revoke():
if 'google_token' in session:
token = session['google_token']
if not token is None:
try:
request = urllib.request.Request(
"https://accounts.google.com/o/oauth2/revoke?token=" + token[0])
request.add_header(
"Content-type", "application/x-www-form-urlencoded")
urllib.request.urlopen(request).read()
except Exception as e:
print(e)

Monday, June 25, 2018

python flask mail send example using smtp protocol with google less secure app access

from flask import Flask, Blueprint, url_for
from flask_mail import Mail, Message
import os

mail_settings = {
"MAIL_SERVER": 'smtp.gmail.com',
"MAIL_PORT": 587,
"MAIL_USE_TLS": True,
"MAIL_USE_SSL": False,
"MAIL_USERNAME": 'acc@gmail.com',
"MAIL_PASSWORD": 'password',
"DEBUG": True
}

app = Flask(__name__)
app.config.update(mail_settings)

mail = Mail(app)
site = Blueprint('site', __name__)


@site.route('/')
def index():
return '<a href="' + url_for('site.send') + '">send</a>'


@site.route('/send_mail')
def send():
msg = Message(subject="Hello",
sender=app.config.get("MAIL_USERNAME"),
recipients=["boroog@gmail.com"],
body="This is a test email I sent with Gmail and Python!")
mail.send(msg)
return 'SENT'

# flask_mail сан ашиглахгүй гэвэл доорх код бас ажиллана

# # SMTP_SSL Example
# import smtplib
# # server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
# smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
# smtpserver.ehlo()
# smtpserver.starttls()
# smtpserver.ehlo()
# smtpserver.login("acc@gmail.com", "password")
# # ssl server doesn't support or need tls, so don't call server_ssl.starttls()
# smtpserver.sendmail("acc@gmail.com", "boroog@gmail.com", "test message")
# #server_ssl.quit()
# smtpserver.close()
return 'SENT'


app.register_blueprint(site)


if __name__ == '__main__':
app.run('127.0.0.1', 5000)