Exemplo n.º 1
0
 private void CheckInvite(Invite invite)
 {
     if (invite == null || invite.ExpiryDate < DateTime.UtcNow || invite.IsUsed)
     {
         ContextAccessor.SetModelError("linkkey", "Invalid or expired link");
         ContextAccessor.ThrowIfModelInvalid();
     }
 }
Exemplo n.º 2
0
        public UserModel ConfirmRegistration(string linkKey, int phoneCode)
        {
            var invite = _inviteRepository.GetByLinkKey(linkKey);

            CheckInvite(invite);
            if (invite.PhoneCode != phoneCode)
            {
                ContextAccessor.SetModelError("phoneCode", "Invalid phone code");
                ContextAccessor.ThrowIfModelInvalid();
            }

            invite.IsConfirmPhoneCode = true;
            _inviteRepository.Save(invite);
            return(_mapper.Map <UserModel>(_userRepository.GetById(invite.IdUser)));
        }
Exemplo n.º 3
0
        public void SendRegistrationCode(string linkKey)
        {
            var invite = _inviteRepository.GetByLinkKey(linkKey);

            CheckInvite(invite);
            if (invite.PhoneCode != 0)
            {
                ContextAccessor.SetModelError("phoneCode", "Code has been sent yet");
                ContextAccessor.ThrowIfModelInvalid();
            }

            var verificationCode = SecurityExtensions.GetVerificationCode();
            var user             = _userRepository.GetById(invite.IdUser);

            _messengerService.SendSms(user.Phone, $"Your code: {verificationCode}");
            invite.PhoneCode = verificationCode;
            _inviteRepository.Save(invite);
        }