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)
 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();
 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')
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)