Ejemplo n.º 1
0
    def __init__(self):
        self.utility = Utility()
        self.registerService = RegisterService()
        dh = LogDBHandler(config=config, request=request)
        log.addHandler(dh)

        self.__getMasterData()
Ejemplo n.º 2
0
 def __init__(self, ):
     
     print "init RegisterController"
     self.utility = Utility();  
     self.sendMailService = SendMailService();
     self.registerService = RegisterService();
     
     dh = LogDBHandler( config=config,request=request);        
     log.addHandler(dh)
Ejemplo n.º 3
0
 def __init__(self):
     dh = LogDBHandler( config=config,request=request);        
     log.addHandler(dh)
     
     self.registerService = RegisterService();
     self.sendMailService = SendMailService();
     
     self.utility = Utility();
     self.urlServer =  model.SystemEnvironment.getServerUrl();
Ejemplo n.º 4
0
 def __init__(self):
     
     
     self.register = RegisterController();
     self.activate = ActivateController()
     self.account = AccountController();
     self.survey = SurveyController();
     self.script = ScriptController();
     self.model = ScriptModelController();
     
     self.images = ImagesController();
     self.preview = PreviewController();
    
     
     self.ans = AnswerQuestionController() #AnswerController();
     
     
     self.ang = AngularController();
     
     self.home = ListSurveyController();
     self.voter = VoterController();
     
     self.sendMailC = SendMailController();
     
     self.registersocial = RegisterWithSocialController()
     #acc = AccountSysController();
     
     self.about = AboutController()
     self.policy = PolicyController()
     self.login = LoginController()
     self.forgot = ForgotController()
     self.service = ServiceController()
     self.support = SupportController()
     self.marketing = MarketingController()
     self.howitwork = HowItWorkController()
     self.example = ExampleController()
     self.webservice = InterfaceServiceController()
     self.lang = LanguageController()
     self.manual = ManualController()
     self.gen = GenpollController();
     
     
     
     self.DEPLOY_DIR = config['path_upload_file_deploy'] ;
     self.sendMailService = SendMailService();
     self.registerService = RegisterService();
     self.utility = Utility();
     
     
      
     dh = LogDBHandler( config=config,request=request);        
     log.addHandler(dh)
     
     self.urlServer =  model.SystemEnvironment.getServerUrl();
Ejemplo n.º 5
0
class RootController(BaseController):
    """
    The root controller for the PollandSurvey application.

    All the other controllers and WSGI applications should be mounted on this
    controller. For example::

        panel = ControlPanelController()
        another_app = AnotherWSGIApplication()

    Keep in mind that WSGI applications shouldn't be mounted directly: They
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.

    """
    secc = SecureController()
    admin = AdminController(model, DBSession, config_type=TGAdminConfig)
    error = ErrorController()
    
    def __init__(self):
        
        
        self.register = RegisterController();
        self.activate = ActivateController()
        self.account = AccountController();
        self.survey = SurveyController();
        self.script = ScriptController();
        self.model = ScriptModelController();
        
        self.images = ImagesController();
        self.preview = PreviewController();
       
        
        self.ans = AnswerQuestionController() #AnswerController();
        
        
        self.ang = AngularController();
        
        self.home = ListSurveyController();
        self.voter = VoterController();
        
        self.sendMailC = SendMailController();
        
        self.registersocial = RegisterWithSocialController()
        #acc = AccountSysController();
        
        self.about = AboutController()
        self.policy = PolicyController()
        self.login = LoginController()
        self.forgot = ForgotController()
        self.service = ServiceController()
        self.support = SupportController()
        self.marketing = MarketingController()
        self.howitwork = HowItWorkController()
        self.example = ExampleController()
        self.webservice = InterfaceServiceController()
        self.lang = LanguageController()
        self.manual = ManualController()
        self.gen = GenpollController();
        
        
        
        self.DEPLOY_DIR = config['path_upload_file_deploy'] ;
        self.sendMailService = SendMailService();
        self.registerService = RegisterService();
        self.utility = Utility();
        
        
         
        dh = LogDBHandler( config=config,request=request);        
        log.addHandler(dh)
        
        self.urlServer =  model.SystemEnvironment.getServerUrl();
         
        
    def _before(self, *args, **kw):
        tmpl_context.project_name = "pollandsurvey"
    
    
    
    @expose('pollandsurvey.templates.ads')
    def ads(self, came_from=lurl('/')):
        
        #print request.scheme   + '://';
        #hooks.notify('tgext.pylogservice.startup' ) 
        #hooks.notify('tgext.pyutilservice.startup')
        
        return dict(page='metronic')
        
    @expose('pollandsurvey.templates.metronic')
    def index_old(self, came_from=lurl('/')):
        
        #print request.scheme   + '://';
        #hooks.notify('tgext.pylogservice.startup' ) 
        #hooks.notify('tgext.pyutilservice.startup')
        
        return dict(page='metronic') 
    
    @expose('pollandsurvey.templates.index_theme2')
    def index(self, came_from=lurl('/')):
        
        #print request.scheme   + '://';
        #hooks.notify('tgext.pylogservice.startup' ) 
        #hooks.notify('tgext.pyutilservice.startup')
        
        if not request.identity:
            ManageSession.deleteAll()
            
        if ManageSession.getLanguage() is None:
            ManageSession.setLanguage()
            
        print 'Session Language : %s' %(ManageSession.getLanguage())
        
        
        
        
        return dict(page='metronic') 
     
        
       
    
    
    @expose('pollandsurvey.templates.environ')
    @require(predicates.has_permission('manage', msg=l_('Only for managers')))
    def environ(self):
        """This method showcases TG's access to the wsgi environment."""
        return dict(page='environ', environment=request.environ)

     
    
    @expose('pollandsurvey.templates.index')
    @require(predicates.has_permission('manage', msg=l_('Only for managers')))
    def manage_permission_only(self, **kw):
        """Illustrate how a page for managers only works."""
        return dict(page='managers stuff')


    @expose('pollandsurvey.templates.index')
    @require(predicates.is_user('editor', msg=l_('Only for the editor')))
    def editor_user_only(self, **kw):
        """Illustrate how a page exclusive for the editor works."""
        return dict(page='editor stuff')

    
    @expose()
    def redirectHttp(self,*args,**kw):
        print HTTPFound(location='www.pollsurfvey/survey');
        raise HTTPFound(location='about');
    
    
    @expose()
    def post_login(self, came_from=lurl('/'), *args, **kw):

        log.info("post_login"); 
        
        if not request.identity:
            log.warning("user cannot login, redirect to login");
            login_counter = request.environ.get('repoze.who.logins', 0) + 1
            
            log.info( self.urlServer + '/login')
            redirect('/login', params=dict(came_from=came_from, __logins=login_counter))
            
        #userid = request.identity['repoze.who.userid'];
        user =  request.identity['user'];
        groups = request.identity['groups'] ;
        
        log.info("user in group : %s " %groups );
        
        userActive = model.UserGenCode.getUserActivated(user.user_id);
        
        if(userActive is None ):# and ('managers' not in groups  )):
            log.warning("user cannot login, redirect to login");
            flash(_('Please activate in your email'), 'warning') 
            #request.identity.current.logout();
            
            self.registerService.reActivateUser(user)
            
            auth_force_logout()
            login_counter = request.environ.get('repoze.who.logins', 0) ;
            
            redirect( '/login')#, params=dict(came_from=came_from, __logins=login_counter))
        
        print "add session"
        ManageSession.setLanguage('EN')
            
        #flash(_('Welcome back, %s!') % userid)
        
        if('/' == came_from):
            if ('voter' in groups):
                log.info("redirect to home page");
                #model.LogSurvey.insert(ip_server='127.0.0.1',status='INFO',message="redirect to home page" ,current_page='Login',user_name=user);
                log.info(self.urlServer + '/home' );
                redirect( '/home');
            if ('creator' in groups):
                log.info("redirect to create survey page");
                log.info(self.urlServer + '/survey' );
                #model.LogSurvey.insert(ip_server='127.0.0.1',status='INFO',message="redirect to create survey page" ,current_page='Login',user_name=user);
                redirect('/survey');
        
        
        
        #identity = request.environ.get('repoze.who.identity') 
        
        
        #for key in request.environ:
        #    print key 
        #    print request.environ[key];
        #    print '-------'
        #print "----------------------------------------------------------------";
        #for key in request.identity:
        #    print key 
        #    print request.identity[key];
        #    print '-------'
        #print "----------------------------------------------------------------";
        
        #print "User id "  ;
        #user =  request.identity['user'];
        #print user.user_id;
        
        """
        
        if 'voter' in groups:
            print "voter";
            log.info('voter');
            return HTTPFound(location='/survey')
        
        print "other";
        
        """
        
        
        
        # Do not use tg.redirect with tg.url as it will add the mountpoint
        # of the application twice.
        return HTTPFound(location=came_from)

    @expose()
    def post_logout(self, came_from=lurl('/'), *args, **kw):
        """
        Redirect the user to the initially requested page on logout and say
        goodbye as well.

        """
        #flash(_('We hope to see you soon!'))
        ManageSession.deleteAll();
        
        return HTTPFound(location=came_from)
    
    
    @expose('pollandsurvey.templates.expired')
    def expired(self,*args,**kw):
        return dict(page='expired');
    
    @expose('pollandsurvey.templates.thankyou')
    def thankyou(self,*args,**kw):
         
        return dict(page='thankyou');
     
        
        
    @expose('pollandsurvey.templates.sanpleuploadfile')
    def sampleupload(self,*args,**kw):
    
        return dict(view="sample");
    
   
    
     
    
    @expose('pollandsurvey.templates.register.register_success')
    def sample(self):
        from webob.exc import HTTPFound, HTTPUnauthorized
         
        app = request.environ['repoze.who.api'];# = HTTPUnauthorized()
         
        
        del request.environ['repoze.who.identity']
        #identify = request.environ['repoze.who.plugins']['main_identifier'].identify(request.environ);
        #print request.environ['repoze.who.plugins']['main_identifier'].forget(request.environ,identify);  
        #repoze_api.logout();
        #for key in request.environ:   print "%s --- %s"   %(  key, request.environ[key]);
        return dict(page='register_success')
    
    
    
    
    @expose('json')
    @require(predicates.not_anonymous(  msg=l_('Only for Authen')))
    def getHistoryEmail(self,*arg, **kw):
         
        self.page = kw.get('page');
        self.pagesize = kw.get('pagesize');
        
        if(self.page is None):
            self.page =1
        
        if(self.pagesize is None):
            self.pagesize =10    
        
        log.info( "page : %s " %self.page);
        log.info( "page size : %s " %self.pagesize);
    
         
        user =  request.identity['user'];
        
        
        log.info( "user_id : %s" %user.user_id);
        
        listSurvey = model.Voter.getListSurveyByMember(user.user_id,int(self.page) -1 ,int(self.pagesize));
                
        return dict(historys = listSurvey);
    
    
   
         
    @expose('json') 
    @require(predicates.not_anonymous(  msg=l_('Only for Authen')))
    def showpassword(self,came_from=lurl('/')):
         
        user =  request.identity['user']; 
        
        password = user.password.encode('utf-8');
        
        log.info( 'old password : %s , new password : %s ' %(user.password, password));
         
        
        password = '******';
        from hashlib import sha256
        import os
        
        salt = sha256()
        salt.update(os.urandom(60))
        salt = salt.hexdigest()
        
        print 'salt : %s , length : %s ' %(salt, str(len(salt)));
        
        hash = sha256()
        # Make sure password is a str because we cannot hash unicode objects
        
        print "orig : %s , salt : %s "   %(password, salt);
        hash.update((password + salt).encode('utf-8'))
        
        #0101877a2d04060e2b34b96fbd4f14d59db5e4b3495bcaa53ee10530556b714f  =
        
        hash = hash.hexdigest()
        
        print 'hash2 : %s ' %(hash);
        
        password = salt + hash

        print 'password : %s ' %(password);
        
        enpassword = password[64:];
        print 'password : %s ' %(enpassword);
        
        repassword = sha256();
        repassword.update(enpassword);
        
        out = repassword.digest().encode('hex');
        print 'repassword : %s ' %(out);
        #check
        newpassword = '******'
        hash = sha256()
        hash.update((newpassword + password[:64]).encode('utf-8'));
        
        print 'old : %s'  %password[64:];
        print 'new : %s' %hash.hexdigest();
        
        
        # Make sure the hashed password is a unicode object at the end of the
        # process because SQLAlchemy _wants_ unicode objects for Unicode cols
        password = password.decode('utf-8')
        
        
        return dict(password = password)
        
    
        
      
    
          
    
    @expose('pollandsurvey.templates.uploadfile')     
    @require(predicates.in_any_group('managers', msg=l_('Only for Admin'))) 
    def uploadfile(self,*arg,**kw):
        return dict(page='uploadfile')
    
    
    @expose('pollandsurvey.templates.uploadfile')      
    @require(predicates.in_any_group('managers', msg=l_('Only for Admin')))
    def savefile(self,*arg,**kw):
        print arg;
        print kw;
        
        reload(sys).setdefaultencoding('utf8')
        print kw.get('file');
        fileUpload = kw.get('file');
        data = fileUpload.file.read();
        file_name=  fileUpload.filename
        
        target_file_name = self.DEPLOY_DIR + file_name;  
        
        f = open(target_file_name, 'wb')
        f.write(data)
        f.close()
        
        return dict(page='uploadfile')
    

    
    @expose('json')
    def postMessagefacebook(self):
        url = 'http://graph.facebook.com/151177958578696/feed?message=test&access_token=CAALWq7buVTYBAKfJL6Bm1VQFeDE3uKC7K9OdxIqqwKl7T8jmcezeIxDsSQvtn1HtODcI6uIwCJ1SqdzzZBDacMxn14ZA3uEGhCkZAhYQZC1ktQCt3lJ84mYAtxYga1aCkzLq52uxhqNl2r17ZCppSf0IGOmpBVSShL8rJZB0Bn19VyGRMe5EP6rOxmdwXguxQZD'
        import urllib2
        from urllib2 import Request, urlopen, URLError, HTTPError
        req = urllib2.Request(url)
        try: 
            urllib2.urlopen(req)
        except URLError as e:
            
            print e.reason   
            
    @expose()
    def userRegister(self):
        #https://www.jobsmatcher.com/JMWeb/register/registerApplicant-init.htm?user.beanEng.username=tong_pa@hotmail.com&apPiPersonalData.gender.idGender=1
        #dd = dict ('user.beanEng.username'= '*****@*****.**','apPiPersonalData.gender.idGender'= 1)
        dd = { 'user.beanEng.username' : '*****@*****.**','apPiPersonalData.gender.idGender': 1, 'contactEmail':'S',
              'user.beanOtherLang.firstName': 'padungrat','user.beanOtherLang.lastName' : 'makchu',
              'user.beanEng.firstName' : 'ผดุงรัฐ', 'user.beanEng.lastName' : 'มากชู',}
        
        redirect('//www.jobsmatcher.com/JMWeb/register/registerApplicant-init.htm', params=dd)
        
        
    @expose('pollandsurvey.templates.showConvertPDF2')   
    def showConvertPDF(self, **kw):
        reload(sys).setdefaultencoding("utf-8");
        
        certificateUser = dict(
                               title="Certificate Of Jobsmatcher",
                               label_score='scored', 
                               label_date='Date', 
                               name="ผดุงรัฐ มากชู", 
                               score="12/20", 
                               type="Positive Attitude test", 
                               finishDate='01 Jan. 2016'
                               )
        
        
        return dict(page = 'showConvertPDF',certificateUser = certificateUser)
Ejemplo n.º 6
0
class RegisterController(BaseController):
    """
    The root controller for the PollandSurvey application.

    All the other controllers and WSGI applications should be mounted on this
    controller. For example::

        panel = ControlPanelController()
        another_app = AnotherWSGIApplication()

    Keep in mind that WSGI applications shouldn't be mounted directly: They
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.

    """
    
    def __init__(self, ):
        
        print "init RegisterController"
        self.utility = Utility();  
        self.sendMailService = SendMailService();
        self.registerService = RegisterService();
        
        dh = LogDBHandler( config=config,request=request);        
        log.addHandler(dh)

    def _before(self, *args, **kw):
        tmpl_context.project_name = "pollandsurvey"

    @expose('pollandsurvey.templates.register.index')
    def index(self, *args, **kw):
        """Handle the front-page."""
        return dict(page='index')

       
    @expose('json')
    @expose('pollandsurvey.templates.register.register_success')
    def create(self,*args,**kw):
        
        log.info(kw);
        print kw
        print len(kw)
        if len(kw) == 0:
            redirect( '/login')
        
        try:
            self.email = kw.get('email');
            self.password = kw.get('password');
            self.rpassword = kw.get('rpassword');
            
            self.success= True;
            self.message = "create success";
            self.urlServer =  model.SystemEnvironment.getServerUrl();
            
            u = model.User.by_email_address(self.email);
            if u is None:
                 
                if( str(self.password) ==  str(self.rpassword) ):
                    
                     
                    self.user,self.userGenCode = self.registerService.createUser(kw);
                    
                    self.emailValues={};
                    self.emailValues['user_name'] = self.user.display_name;
                    self.emailValues['email'] = self.user.email_address;
                    self.emailValues['password'] = self.password;
                    self.emailValues['activate_url'] =  request.scheme   + '://' + self.urlServer + "/activate/value/" + str(self.userGenCode.code);  #request.application_url
                    
                    self.sendMailService = SendMailService();
                    self.sendMailService.sendActivate(self.emailValues);
                    self.sendMailService.start();
                        
                    log.info("create user : %s " , self.email);
                    
                    
                else:
                    self.message ="password not same";
                    self.success= False;
                    log.info("password not same : %s " , self.email);
                 
            else:
                self.message = "email have already";
                self.success= False;
                log.info("email have already : %s " , self.email);
            u =None;
        except Exception as inst:
            log.error("error : %s " %inst);
            flash(_(LanguageObject.getdata("msg_error_data_register")), 'warning')   
            redirect( '/login')
        return dict(success=self.success, message = self.message);
    
    @expose('pollandsurvey.templates.register.register_success')
    def registerSuccess(self,*args,**kw):
        
        return dict(page='register_success')
    
    
    @expose( )
    def checkUserEmail(self,*args,**kw):
        
        self.email = kw.get('email');
        u = model.User.by_email_address(self.email);
        if u is None:
            return "true";
        return "false";
    
    
    @expose()
    #@validate(RegisterForm, error_handler=index)    
    def create_old(self,*args,**kw):
        
        return str(kw);
        flash(_('Wrong credentials'), 'warning')
        email =  kw['registerform:email_address'];
        user = kw['registerform:user_name'];
        confirm_password =  kw['registerform:confirm_password'];
        user_id = kw['registerform:user_id'];
        display = kw['registerform:display_name'];
        password = kw['registerform:password'];
        
        #u = model.User();
        msg ="";
        u = model.User.by_email_address(email);
        if u is None:
            u = model.User.by_user_name(user);
            if u is None:
                log.info("password : "******" , confirm password : "******"same password")
                    u= model.User();
                    u.user_name = user
                    u.display_name = display
                    u.email_address = email
                    u.password = password
                    
                    
                    #model.DBSession.add(u)
                    model.DBSession.flush()
                    log.info( "save user success");
                else:
                    msg ="password not same";
                    log.info( "password not same");
            else:
                msg = "user have already";
                log.info( "user have already");
        else:
            msg = "email have already";
            log.info( "email have already");
Ejemplo n.º 7
0
class ActivateController(BaseController):
    # Uncomment this line if your controller requires an authenticated user
    # allow_only = predicates.not_anonymous()
    
    def __init__(self):
        dh = LogDBHandler( config=config,request=request);        
        log.addHandler(dh)
        
        self.registerService = RegisterService();
        self.sendMailService = SendMailService();
        
        self.utility = Utility();
        self.urlServer =  model.SystemEnvironment.getServerUrl();
        
        
    @expose()
    def index(self,*args,**kw):
        redirect( '/login')
    
     
    
    @expose('json')
    @expose('genshi:pollandsurvey.templates.register.activate_success')
    def value(self,*args, **kw):
        
        self.activate_code = args
        if(len(self.activate_code) > 0): 
            self.userGenCode =  model.UserGenCode.getByActivateCode(self.activate_code[0])
            self.message = "";
            
            if (self.userGenCode ):
                if ( not self.utility.convertToBool(self.userGenCode.success) ):
                    
                    if (self.utility.isActiveFromDate(self.utility.getCurrentDate() , self.userGenCode.create_date ,self.userGenCode.expire_date   ) ):
                        self.userGenCode.success = 1;
                        self.message =   LanguageObject.getdata("msg_success_activate")  
                        
                    else : 
                        self.message = LanguageObject.getdata("msg_expire_activate") 
                          
                        override_template(ActivateController.value, 'genshi:pollandsurvey.templates.register.reactivate') 
                         
                else:
                    self.message = LanguageObject.getdata("msg_already_activate")
                    
            
            else:
                self.message = LanguageObject.getdata("msg_not_found_activate")
                log.warning("Find not found activate code  %s", self.activate_code )
        else:
            #self.message = "Thank you!";
            log.warning("User income is wrong,have not activate code")
            redirect("/")
         
        
        #for key in request.environ:   print "%s --- %s"   %(  key, request.environ[key]);
         
        return dict(page='activate_success',message = self.message) 
        
    
    @expose('pollandsurvey.templates.register.register_success')
    def reactivate(self,*args,**kw):
         
        if(kw.get('activate_code')):
            self.userGenCode =  model.UserGenCode.getByActivateCode(kw.get('activate_code'));
            if self.userGenCode :
                self.user = model.UserService.getByUserId(self.userGenCode.user_id);
                
                self.userGenCode = self.registerService.reActivateUserGenCode(self.userGenCode,self.user);
                
                self.emailValues={};
                self.emailValues['user_name'] = self.user.display_name;
                self.emailValues['email'] = self.user.email_address;
                # self.emailValues['password'] = self.password;
                self.emailValues['activate_url'] = request.application_url + "/activate/value/" + str(self.userGenCode.code);
               
                self.sendMailService = SendMailService();
                self.sendMailService.sendreActivate(self.emailValues);
                self.sendMailService.start();
            else:
                log.warn("user gen code is not exits ")    
        
        return dict(page='register_success')

    @expose('pollandsurvey.templates.message.index')
    def canceldeactive(self,*args,**kw):
        
        self.title ="test"
        self.message =  LanguageObject.getdata("msg_already_deactivate")
        
        if(len(args) >0 and args[0] != None):
            self.userGenCode =  model.UserGenCode.getByDeactivateCode(args[0]);
            if self.userGenCode:
                self.user = model.User.getId(self.userGenCode.user_id)
                self.user.active = 1
                self.userGenCode.success = 0
                
                
                self.emailValues={};
                self.emailValues['user_name'] = self.user.display_name;
                self.emailValues['email'] = self.user.email_address;
                # self.emailValues['password'] = self.password;
                
               
                self.sendMailService = SendMailService();
                self.sendMailService.sendWelcomeActivate(self.emailValues);
                self.sendMailService.start();
                
                
                self.message =LanguageObject.getdata("msg_success_deactivate")  
        else:
            self.message = LanguageObject.getdata("failed")       
                
        
        
        return dict(page='canceldeactivate', title=self.title, message=self.message)
Ejemplo n.º 8
0
class AccountController(BaseController):
    def __init__(self):
        self.utility = Utility()
        self.registerService = RegisterService()
        dh = LogDBHandler(config=config, request=request)
        log.addHandler(dh)

        self.__getMasterData()

    def _before(self, *args, **kw):
        tmpl_context.project_name = "pollandsurvey"

    def __getMasterData(self):
        self.serviceType = model.SocialType.getAll(1)

    @expose("pollandsurvey.templates.account.index")
    @require(predicates.not_anonymous())
    def index(self, *args, **kw):

        userService = model.UserService()
        if request.identity:
            user = request.identity["user"]
            userService = model.UserService.getById(user.user_id)
            if userService is None:
                userService = model.UserService()

        listConutry = []
        self.country = model.FixCountry.getAll("1")
        for lang in self.country:
            listConutry.append(lang.to_json())

        listGender = model.Gender.getAll(1)
        listLanguage = []

        self.language = model.FixLanguage.getAll("1")
        for lang in self.language:
            listLanguage.append(lang.to_json())

        return dict(
            page="index",
            userService=userService,
            listConutry=listConutry,
            listGender=listGender,
            listLanguage=listLanguage,
        )

    @expose("pollandsurvey.templates.account.changepassword")
    @require(predicates.not_anonymous())
    def changepass(self, *args, **kw):
        """Handle the front-page."""
        return dict(page="changepassword")

    @expose("pollandsurvey.templates.account.socialmedia")
    @require(predicates.not_anonymous())
    def socialmedia(self, *args, **kw):
        user = request.identity["user"]
        self.userSocialNetwork = model.UserSocialNetwork.getSocialByUserId(user.user_id)
        return dict(page="socialmedia", userSocialNetwork=self.userSocialNetwork, socialType=self.serviceType)

    @expose("pollandsurvey.templates.account.cancellation")
    @require(predicates.not_anonymous())
    def cancellation(self, *args, **kw):
        """Handle the front-page."""
        return dict(page="cancellation")

    @expose()
    @require(predicates.not_anonymous())
    def deactivate(self):
        self.user = request.identity["user"]
        self.user.active = 0
        # user.deactivate()

        self.urlServer = model.SystemEnvironment.getServerUrl()
        self.userGenCode = self.registerService.deActivateUserGenCode(self.user)

        self.emailValues = {}
        self.emailValues["user_name"] = self.user.display_name
        self.emailValues["email"] = self.user.email_address
        self.emailValues["deactivate_url"] = (
            request.scheme + "://" + self.urlServer + "/activate/canceldeactive/" + str(self.userGenCode.code)
        )
        # request.application_url

        self.sendMailService = SendMailService()
        self.sendMailService.senddeActivate(self.emailValues)
        self.sendMailService.start()

        # model.User.deactivate()
        flash(_(LanguageObject.getdata("msg_thank_you")), "warning")
        redirect("/logout_handler")

    @expose()
    @require(predicates.not_anonymous())
    def updateprofile(self, *args, **kw):

        if request.identity:

            self.user = request.identity["user"]
            self.userService = model.UserService.getById(self.user.user_id)
            if self.userService is None:
                self.userService = model.UserService()
            self.userService.updateByValue(**kw)
            self.userService.accept_tnc = 1
            self.userService.user_id = self.user.user_id
            self.userService.birthdate = self.utility.convertToDateTime(self.userService.birthdate, "%d/%m/%Y")
            self.userService.updateall()

            flash(_(LanguageObject.getdata("msg_save_success")), "warning")
        else:

            log.warning("user cannot login, redirect to login")
            flash(_(LanguageObject.getdata("msg_not_login")), "warning")

        redirect("/account")

    @expose()
    # @expose('json')
    # @expose('json',content_type="text/plain"  )
    @require(predicates.not_anonymous())
    def rechangepass(self, *args, **kw):

        self.success = False
        self.message = ""
        if request.identity:
            self.current_password = kw.get("password")
            self.new_password = kw.get("newpassword")
            self.re_new_password = kw.get("rnewpassword")
            user = request.identity["user"]

            if user.validate_password(self.current_password):
                if str(self.new_password) == str(self.re_new_password):
                    user._set_password(self.new_password)
                    self.success = True
                    self.message = LanguageObject.getdata("msg_password_changed")
                else:
                    self.message = LanguageObject.getdata("msg_password_not_match")

            else:
                log.warning("user %s password not match : %s", user.user_name, self.current_password)
                self.message = LanguageObject.getdata("msg_password_not_match")
        else:
            self.message = LanguageObject.getdata("msg_not_login")
            log.warning("user cannot login, redirect to login")

        flash(_(self.message), "warning")
        # return dict(success=self.success, message = self.message);

        redirect("/account/changepass")