summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/rest_api.py
blob: 0a15aad14f059b032548666094ca7d87a46f3c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from odoo import models
import datetime
from pytz import timezone
import hashlib


class RestApi(models.TransientModel):
    _name = 'rest.api'

    def datetime_to_str(self, object, format):
        time = ''
        if isinstance(object, datetime.datetime):
            time = object.astimezone(timezone('Asia/Jakarta')).strftime(format)
        return time
    
    def md5_salt(self, value, salt):
        return hashlib.md5((salt + '$' + str(value)).encode()).hexdigest()

    def md5_salt_valid(self, value, salt, token):
        return hashlib.md5((salt + '$' + str(value)).encode()).hexdigest() == token