Beispiel #1
0
        public async Task <bool> SignInStepOne(SignInStepOneViewModel model)
        {
            var    phone = model.PhoneNumber.Trim().ToNormalPhoneNumber();
            Random rnd   = new Random();
            var    code  = rnd.Next(100000, 999999).ToString();

            if (!await _context.Users.AnyAsync(w => w.PhoneNumber == phone))
            {
                var userAdd = new User
                {
                    PhoneNumber            = phone,
                    RoleEnum               = (int)RoleEnum.User,
                    SecurityCode           = code,
                    SecurityCodeExpiration = DateTime.Now.AddMinutes(3)
                };
                _context.Users.Add(userAdd);
                await _context.SaveChangesAsync();
            }
            else
            {
                var user = await _context.Users.FirstOrDefaultAsync(w => w.PhoneNumber == phone);

                user.SecurityCode           = code;
                user.SecurityCodeExpiration = DateTime.Now.AddMinutes(3);
                await _context.SaveChangesAsync();
            }

            //ارسال کد فعالسازی از طریق پیامک
            return(_smsHelper.SendSecurityCode(phone, code));
        }