<commit_before>module(..., package.seeall)


local Model = require 'bamboo.model'
local Session = require 'bamboo.session'
local md5 = require 'md5'


local User = Model:extend {
    __tag = 'Bamboo.Model.User';
	__name = 'User';
	__desc = 'Basic user definition.';
	__indexfd = "username";
	__fields = {
		['username'] = { required=true, unique=true },
		['password'] = { required=true },
		['email'] = { required=true },
		['nickname'] = {},
		['forwhat'] = {},
		['is_manager'] = {},
		['is_active'] = {},	
		['created_date'] = {},
		['lastlogin_date'] = {},
		['is_logined'] = {},
		
		['perms'] = { foreign="Permission", st="MANY" },
		['groups'] = { foreign="Group", st="MANY" },
	};
	

	init = function (self, t)
		if not t then return self end
		
		self.username = t.username
		self.email = t.email
		self.nickname = t.nickname
		self.forwhat = t.forwhat
		self.is_manager = t.is_manager
		self.is_active = t.is_active
		self.created_date = os.time()

		if t.encrypt and type(t.encrypt) == 'function' then
			self.password = t.encrypt(t.password or '')
		else
			self.password = <PASSWORD>(t.password or '')
		end
		
		return self
	end;
	
	
	authenticate = function (self, params)
		I_AM_CLASS(self)

		local user = self:getByIndex(params.username)
		if not user then return false end
		-- if md5.sumhexa(params.password):lower() ~= user.password then
		if params.password:lower() ~= user.password then
			return false
		end<commit_msg>modify the encrypt feature of models.user<commit_after>module(..., package.seeall)


local Model = require 'bamboo.model'
local Session = require 'bamboo.session'
local md5 = require 'md5'


local User = Model:extend {
    __tag = 'Bamboo.Model.User';
	__name = 'User';
	__desc = 'Basic user definition.';
	__indexfd = "username";
	__fields = {
		['username'] = { required=true, unique=true },
		['password'] = { required=true },
		['email'] = { required=true },
		['nickname'] = {},
		['forwhat'] = {},
		['is_manager'] = {},
		['is_active'] = {},	
		['created_date'] = {},
		['lastlogin_date'] = {},
		['is_logined'] = {},
		
		['perms'] = { foreign="Permission", st="MANY" },
		['groups'] = { foreign="Group", st="MANY" },
	};
	

	init = function (self, t)
		if not t then return self end
		
		self.username = t.username
		self.email = t.email
		self.nickname = t.nickname
		self.forwhat = t.forwhat
		self.is_manager = t.is_manager
		self.is_active = t.is_active
		self.created_date = os.time()

		-- if t.encrypt and type(t.encrypt) == 'function' then
		-- 	self.password = t.encrypt(t.password or '')
		-- else
		-- 	self.password = <PASSWORD>(t.password or '')
		-- end
		
		if self.encrypt and type(self.encrypt) == 'function' then
			self.password = self.encrypt(t.password or '')
		end

		return self
	end;
	
	encrypt = md5.sumhexa; 
	
	authenticate = function (self, params)
		I_AM_CLASS(self)

		local user = self:getByIndex(params.username)
		if not user then return false end
		-- if md5.sumhexa(params.password):lower() ~= user.password then
		-- if params.password:lower() ~= user.password then
		if self.encrypt and type(self.encrypt) == 'function' then
			if self.encrypt(params.password):lower() ~= user.password then
				return false
			end
		else
			print(params.password, user.password)
			if (params.password):lower() ~= user.password then
				return false
			end
		end
{'fraction_non_alphanumeric': 0.16606714628297362, 'fraction_numerical': 0.0020983213429256594, 'mean_word_length': 3.473190348525469, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1958719', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1146, 'n_words': 269}