Exemple #1
0
        public void SendForgotPasswordEmail(string email)
        {
            var user = _userRepository.Table.FirstOrDefault(x => x.UserEmail == email);

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            var verificationHash = Guid.NewGuid().ToString();

            var verification = _verificationRepository.Table.FirstOrDefault(x =>
                                                                            x.VerificationUserIdFk == user.UserIdPk && x.VerificationType == VerificationType.Password);

            if (verification == null)
            {
                verification = new VerificationEntity
                {
                    VerificationUserIdFk = user.UserIdPk,
                    VerificationHash     = verificationHash,
                    VerificationType     = VerificationType.Password
                };
                _verificationRepository.Insert(verification);
            }
            else
            {
                verification.VerificationHash = verificationHash;
            }

            _verificationRepository.SaveAll();
            _emailService.SendForgotPasswordEmail(email, verificationHash);
        }
        public async Task SaveVerification(Verification verification)
        {
            var verificationsReference = _tableClient.GetTableReference("verifications");
            var verificationEntity     = await verificationsReference.ExecuteAsync(TableOperation.Retrieve <VerificationEntity>(verification.GuildId.ToString(), verification.DiscordId.ToString()));

            var entity = verificationEntity.Result as VerificationEntity;

            if (verificationEntity.HttpStatusCode != 200)
            {
                entity = new VerificationEntity
                {
                    RowKey       = verification.DiscordId.ToString(),
                    PartitionKey = verification.GuildId.ToString()
                };
            }

            entity.Alias               = verification.Alias;
            entity.CorpUserId          = verification.CorpUserId;
            entity.Department          = verification.Department;
            entity.ValidatedOn         = verification.ValidatedOn;
            entity.BypassOrgValidation = verification.BypassOrgValidation;

            await verificationsReference.CreateIfNotExistsAsync();

            await verificationsReference.ExecuteAsync(TableOperation.InsertOrMerge(entity));
        }
Exemple #3
0
        /// <summary>
        /// 设置按钮
        /// </summary>
        /// <param name="verification"></param>
        /// <param name="info"></param>
        protected virtual void AddResourceControl(VerificationEntity verification, ResourceEntity info)
        {
            if (string.IsNullOrEmpty(info.Controls))
            {
                return;
            }
            var ctrls = info.Controls.Split(',');

            foreach (var ctrl in ctrls)
            {
                if (info.IsExcude)
                {
                    if (verification.Controls.ContainsKey(ctrl))
                    {
                        verification.Controls.Remove(ctrl);
                    }
                    verification.Controls.Add(ctrl, false);
                }
                else
                {
                    if (verification.Controls.ContainsKey(ctrl))
                    {
                        verification.Controls.Remove(ctrl);
                    }
                    verification.Controls.Add(ctrl, true);
                }
            }
        }
Exemple #4
0
        public static MvcHtmlString RemoveNoAuthorizeResource(this HtmlHelper htmlHelper)
        {
            if (htmlHelper.ViewBag.Verification == null)
            {
                return(null);
            }
            VerificationEntity verification = htmlHelper.ViewBag.Verification;

            if (verification.Controls == null)
            {
                return(null);
            }
            var builder = new StringBuilder();

            builder.Append("<script type=\"text/javascript\">$(document).ready(function(){");
            foreach (var control in verification.Controls)
            {
                if (control.Value)
                {
                    continue;
                }
                builder.AppendFormat("$(document).find(\"*[name={0}]\").remove();", control.Key);
            }
            builder.Append("</script>");
            return(new MvcHtmlString(builder.ToString()));
        }
Exemple #5
0
 public static Verification ToModel(this VerificationEntity verification)
 {
     return(new Verification()
     {
         Id = verification.Id,
         PhoneNumber = verification.PhoneNumber,
         StartTime = verification.StartTime,
         Code = verification.Code
     });
 }
Exemple #6
0
        public Verification AddVerification(Verification verification)
        {
            try
            {
                if (verification == null)
                {
                    return(null);
                }

                DbParameter[] parameters = new DbParameter[]
                {
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfVerification.Sp_Insert_Verification_PhoneNumber,
                        Value         = verification.PhoneNumber
                    },
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfVerification.Sp_Insert_Verification_Code,
                        Value         = verification.Code
                    }
                };

                using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfVerification.Sp_Put_Verification, parameters))
                {
                    VerificationEntity entity = null;

                    if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0)
                    {
                        DataRow dataRow = dataSet.Tables[0].Rows[0];
                        DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                        entity = new VerificationEntity()
                        {
                            Id          = (int)dataRow[dataColumns[0]],
                            PhoneNumber = dataRow[dataColumns[1]].ToString(),
                            StartTime   = (DateTime)dataRow[dataColumns[2]],
                            Code        = dataRow[dataColumns[3]].ToString()
                        };
                    }

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

                    return(entity.ToModel());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// 设置控件
 /// </summary>
 /// <param name="page"></param>
 /// <param name="info"></param>
 private static void SetResourceControl(this Page page, VerificationEntity info)
 {
     if (!info.IsPass)
     {
         return;
     }
     foreach (var ctrl in info.Controls)
     {
         SetPageControl(page, ctrl.Key, ctrl.Value);
     }
 }
Exemple #8
0
        public Verification AddOrUpdateVerification(Verification verification)
        {
            VerificationEntity entity = this.dbContext.Verifications.FirstOrDefault(v => v.PhoneNumber == verification.PhoneNumber);

            if (entity == null)
            {
                entity = verification.ToEntity();
                this.dbContext.Verifications.Add(entity);
                this.dbContext.SaveChanges();
                return(entity.ToModel());
            }
            else
            {
                entity.StartTime = DateTime.Now;
                entity.Code      = verification.Code;
                this.dbContext.SaveChanges();
                return(entity.ToModel());
            }
        }
Exemple #9
0
        /// <summary>
        /// 验证资源
        /// </summary>
        /// <param name="roleIds"></param>
        /// <param name="resourceUrl"></param>
        /// <returns></returns>
        public virtual VerificationEntity GeVerificationEntity(long[] roleIds, string resourceUrl)
        {
            var verification = new VerificationEntity {
                IsPass = true, Controls = new Dictionary <string, bool>()
            };
            var infos = GetResources(roleIds, resourceUrl);

            if (infos == null || infos.Count == 0)
            {
                verification.IsPass = false;
                return(verification);
            }
            if (verification.IsPass)
            {
                foreach (var info in infos)
                {
                    AddResourceControl(verification, info);
                }
            }
            return(verification);
        }
Exemple #10
0
        /// <summary>
        /// 添加日志
        /// </summary>
        public virtual void AddLog(ResultExecutedContext filterContext)
        {
            VerificationEntity verification = filterContext.Controller.ViewBag.Verification;
            string             method       = filterContext.Controller.ViewBag.Method;
            var accountId = verification == null || verification.Voucher == null || verification.Voucher.Account == null
                ? 0
                : verification.Voucher.Account.Id;
            string key  = filterContext.Controller.ViewBag.TraceKey;
            var    info = new ApiTraceEntity
            {
                Method   = method,
                Key      = key,
                Request  = GetRequest(filterContext),
                Response = GetResponse(filterContext),
                Ip       = HttpContextHelper.GetClientIp(),
                Account  = new AccountEntity {
                    Id = accountId
                },
                SaveType = SaveType.Add
            };

            Ioc.Resolve <IApplicationService, ApiTraceEntity>().Save(info);
        }
Exemple #11
0
        public Verification GetVerificationByPhoneNumber(string phoneNumber)
        {
            VerificationEntity entity = this.dbContext.Verifications.FirstOrDefault(v => v.PhoneNumber == phoneNumber);

            return(entity == null ? null : entity.ToModel());
        }
Exemple #12
0
        public Verification GetVerificationById(int id)
        {
            VerificationEntity entity = this.dbContext.Verifications.FirstOrDefault(v => v.Id == id);

            return(entity == null ? null : entity.ToModel());
        }