public async Task <Worker> SignInAsync(SmsDTO smsInfo)
        {
            SMSCode sms = await db.SMSCodes.FirstOrDefaultAsync(s => s.Phone == smsInfo.Phone && s.Code == smsInfo.Code);

            Worker worker = await db.Workers.FirstOrDefaultAsync(c => c.Phone == smsInfo.Phone);

            if (sms == null || worker == null)
            {
                return(null);
            }

            await db.SMSCodes.RemoveAsync(sms);

            worker.ApiKey = encryptService.GenerateHash(sms.Phone, sms.Code.ToString());
            await db.Workers.UpdateAsync(worker);

            return(worker);
        }
        public async Task <string> SignUpAsync(ClientRegisterDTO clientData)
        {
            int    code   = clientData.Code;
            Client client = Mapper.Map <ClientRegisterDTO, Client>(clientData);

            SMSCode sms = await db.SMSCodes.FirstOrDefaultAsync(s => s.Phone == client.Phone && s.Code == code);

            if (sms == null)
            {
                return(null);
            }

            await db.SMSCodes.RemoveAsync(sms);

            string apiKey = encrypt.GenerateHash(client.Phone, code.ToString());

            client.ApiKey = apiKey;
            await db.Clients.CreateAsync(client);

            return(apiKey);
        }
예제 #3
0
        public async Task AddCommpanyAsync(CompanyRegisterDTO companyInfo)
        {
            Company company = Mapper.Map <CompanyRegisterDTO, Company>(companyInfo);

            company.ApiKey = encryptService.GenerateHash(company.Login, company.ContactPhone);
            await db.Companies.CreateAsync(company);

            await db.Users.CreateAsync(new User()
            {
                Login     = company.Login,
                Password  = encryptService.GeneratePassword(company.Login, company.Password),
                CompanyId = company.Id,
                RoleId    = 2
            });
        }