Example #1
0
        private static string GenerateCode(string platform, string business, string uniqueKey, object extensions)
        {
            string codeKey         = $"{platform}:APP:SMSVerification:{business}:{uniqueKey}";
            string codeCacheString = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, codeKey);
            string code;

            if (!string.IsNullOrEmpty(codeCacheString))
            {
                CodeExtension <object> ext = JsonConvert.DeserializeObject <CodeExtension <object> >(codeCacheString);
                code = ext?.Code ?? RandomAlphaNumericGenerator.GenerateAllNumber(6);
            }
            else
            {
                code = RandomAlphaNumericGenerator.GenerateAllNumber(6);
            }

            CodeExtension <object> codeCache = new CodeExtension <object>
            {
                Code      = code,
                Extension = extensions
            };

            RedisHelper.Set(codeKey, codeCache, TimeSpan.FromMinutes(Constant.SMS_EXPIRED_TIME));
            return(code);
        }
Example #2
0
        /// <summary>
        /// 发送原邮箱验证码 20180523
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        public async Task SendVerifyOriginalEmail(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            var accountByEmail = dac.GetByEmail(emailAddress);

            if (accountByEmail != null && accountByEmail.Id != accountId)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_BINDED, "该邮箱已绑定到其他账户");
            }

            string key  = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            string code = RandomAlphaNumericGenerator.GenerateAllNumber(6);

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "AccountId", accountId.ToString() },
                { "EmailAddress", emailAddress },
                { "Code", code }
            };

            RedisHelper.Set(key, dic, new TimeSpan(0, Constant.EMAIL_EXPIRED_TIME, 0));

            string subject = Resources.验证码邮箱标题;
            string content = string.Format(Resources.验证码邮箱模版, code, Constant.EMAIL_EXPIRED_TIME);

            EmailAgent agent = new EmailAgent();
            await agent.SendAsync(emailAddress, subject, content, 5);
        }
Example #3
0
        public string GenegeToken(SecurityMethod securityMethod)
        {
            var    token    = RandomAlphaNumericGenerator.Generate(16);
            string tokenKey = $"{Platform}:{securityMethod.ToString()}:{SecurityMethod.TempToken.ToString()}:{token}";

            RedisHelper.StringSet(tokenKey, token, TimeSpan.FromMinutes(Constant.TEMPTOKEN_EXPIRED_TIME));
            return(token);
        }
        private string GenerateUniqueName(Mime mime)
        {
            var    dinfo = new DirectoryInfo(RootDirecotry);
            string fname = null;

            do
            {
                fname = Path.Combine(dinfo.FullName, $"{RandomAlphaNumericGenerator.RandomAlphaNumeric(40)}{mime.Extension}");
            }while (File.Exists(fname));
            return(fname);
        }
Example #5
0
        public FileResult ShowImage(string gid)
        {
            byte[] thumb = null;
            string code  = RandomAlphaNumericGenerator.Generate(4);

            try
            {
                thumb = new VerificationCode().CreateImageCode(code);
                RedisHelper.StringSet(gid, code, new TimeSpan(0, 5, 0));
            }
            catch (Exception)
            {
                thumb = System.IO.File.ReadAllBytes(Server.MapPath("~/Content/Images/NoFileFound.png"));
            }
            return(File(thumb, "image/jpg"));
        }
Example #6
0
        public OpenAccount Create(int platform, FiiiType fiiiType, Guid accountId)
        {
            OpenAccount account = new OpenAccount
            {
                CreateTime = DateTime.UtcNow,
                PlatformId = platform,
                FiiiType   = fiiiType,
                OpenId     = Guid.NewGuid(),
                SecretKey  = RandomAlphaNumericGenerator.Generate(32),
                AccountId  = accountId
            };

            long id = new OpenAccountDAC().Create(account);

            account.Id = id;

            return(account);
        }
Example #7
0
        private string GenerateInvitationCode(string code = null)
        {
            if (IsNullOrEmpty(code))
            {
                code = RandomAlphaNumericGenerator.GenerateCode(5);
            }

            var accountDAC = new UserAccountDAC();

            if (accountDAC.ExistInviterCode(code))
            {
                var newCode = RandomAlphaNumericGenerator.GenerateCode(5);
                code = GenerateInvitationCode(newCode);
                return(code);
            }

            return(code);
        }
Example #8
0
        public InfoOM Info(UserAccount user, bool isZH)
        {
            var agent = new UserProfileAgent();

            var profile = agent.GetUserProfile(user.Id);
            var country = new CountryComponent().GetById(user.CountryId);

            if (profile == null)
            {
                var userProfile = new UserProfile
                {
                    Country        = user.CountryId,
                    LastName       = "F" + RandomAlphaNumericGenerator.GenerateCode(8),
                    UserAccountId  = user.Id,
                    Cellphone      = user.Cellphone,
                    L1VerifyStatus = VerifyStatus.Uncertified,
                    L2VerifyStatus = VerifyStatus.Uncertified
                };
                var hasCreate = agent.AddProfile(userProfile);
                if (hasCreate)
                {
                    profile = userProfile;
                    _log.Info("Create profile info success. user id = " + user.Id);
                }
                else
                {
                    _log.Error("Create profile info error. user id = " + user.Id);
                }

                _log.Error("get profile info error, user id = " + user.Id);
            }

            return(new InfoOM
            {
                Avatar = user.Photo,
                Birthday = profile.DateOfBirth?.ToUnixTime().ToString(),
                Cellphone = new UserAccountComponent().GetMaskedCellphone(country.PhoneCode, user.Cellphone),
                CountryName = isZH ? country.Name_CN : country.Name,
                Email = new UserAccountComponent().GetMaskedEmail(user.Email),
                FullName = (string.IsNullOrEmpty(profile.FirstName) ? "" : "* ") + profile.LastName,
                Gender = profile.Gender,
                VerifiedStatus = GetVerifiedStatus(user)
            });
        }
Example #9
0
        public Operation RequestCredentialReset(CredentialMetadata metadata, string targetUser)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var user = _query.GetUserById(targetUser);
            if (user.Status != (int)AccountStatus.Active)
            {
                throw new Exception("invalid account state");
            }

            var verification = _query.GetLatestContextVerification(user, Constants.VerificationContext_CredentialReset);

            //if no unverified context still exists in the db, create a new one
            if (verification == null || verification.Verified || verification.ExpiresOn <= DateTime.Now)
            {
                var expiry = _settingsManager.GetSetting(Constants.Settings_DefaultContextVerificationExpirationTime)
                             .Resolve()
                             .ParseData <TimeSpan>();
                verification = new ContextVerification
                {
                    Context           = Constants.VerificationContext_CredentialReset,
                    Target            = user,
                    ExpiresOn         = DateTime.Now + expiry,
                    VerificationToken = RandomAlphaNumericGenerator.RandomAlphaNumeric(50)
                };

                _pcommand.Add(verification).Resolve();
            }

            return(_backgroundProcessor.EnqueueOperation <IEmailPush>(_mp => _mp.SendMail(new AccountActivation
            {
                From = "*****@*****.**",
                Subject = "Password Reset",
                Target = user.UserId,
                Link = _apiProvider.GeneratePasswordUpdateVerificationUrl(verification.VerificationToken, targetUser).Result,
                LogoUrl = _apiProvider.LogoUri().Result,
                LogoTextUrl = _apiProvider.LogoTextUri().Result
            }))
                   .Then(opr => { }));
        });
Example #10
0
        public string GenerateNickname(string code = null)
        {
            string prevStr = "user_";

            if (IsNullOrEmpty(code))
            {
                code = RandomAlphaNumericGenerator.GenerateCode(10);
            }

            string nickname = prevStr + code;

            var accountDAC = new UserAccountDAC();

            if (accountDAC.ExistInviterCode(nickname))
            {
                var newCode = RandomAlphaNumericGenerator.GenerateCode(10);
                nickname = GenerateNickname(newCode);
                return(nickname);
            }

            return(nickname);
        }
Example #11
0
 private string GenerateToken() => RandomAlphaNumericGenerator.RandomAlphaNumeric(50);
Example #12
0
        private bool Register(int countryId, string cellphone, string password, string inviterCode)
        {
            var country   = new CountryComponent().GetById(countryId);
            var accountId = Guid.NewGuid();

            var userAccount = new UserAccount
            {
                Id                = accountId,
                PhoneCode         = country.PhoneCode,
                Cellphone         = cellphone,
                CountryId         = countryId,
                IsAllowExpense    = true,
                Email             = null,
                IsAllowWithdrawal = true,
                IsVerifiedEmail   = false,
                IsAllowTransfer   = true,
                Password          = PasswordHasher.HashPassword(password),
                Photo             = null,
                Pin               = null,
                RegistrationDate  = DateTime.UtcNow,
                SecretKey         = accountId.ToString().ToUpper(),
                Status            = 1,
                FiatCurrency      = country.FiatCurrency,
                InvitationCode    = GenerateInvitationCode(),
                InviterCode       = inviterCode,
                Nickname          = GenerateNickname(),
                ValidationFlag    = (byte)ValidationFlag.Cellphone
            };

            var userProfile = new UserProfile
            {
                Country        = countryId,
                LastName       = "F" + RandomAlphaNumericGenerator.GenerateCode(8),
                UserAccountId  = userAccount.Id,
                Cellphone      = cellphone,
                L1VerifyStatus = VerifyStatus.Uncertified,
                L2VerifyStatus = VerifyStatus.Uncertified
            };

            var accountDAC    = new UserAccountDAC();
            var agent         = new UserProfileAgent();
            var profileResult = agent.AddProfile(userProfile);

            if (profileResult)
            {
                try
                {
                    accountDAC.Insert(userAccount);
                }
                catch
                {
                    agent.RemoveProfile(userProfile);
                    throw;
                }

                //if (!string.IsNullOrEmpty(inviterCode))
                //{
                //    try
                //    {
                //        new InviteComponent().InsertRecord(new DTO.Invite.InviteRecordIM
                //        {
                //            InvitationCode = inviterCode,
                //            BeInvitedAccountId = userAccount.Id,
                //            Type = SystemPlatform.FiiiPay
                //        });
                //    }
                //    catch (Exception ex)
                //    {
                //        agent.RemoveProfile(userProfile);
                //        accountDAC.RemoveById(userAccount.Id);
                //        Error($"InviteComponent.InsertRecord faild:BeInvitedAccountId={userAccount.Id},InvitationCode={inviterCode},Type={SystemPlatform.FiiiPay.ToString()}", ex);
                //        throw ex;
                //    }
                //}
                return(true);
            }

            throw new CommonException(ReasonCode.GENERAL_ERROR, MessageResources.NetworkError);
        }