Example #1
0
        public override User Add(User entity, long userId = 0)
        {
            if (entity.PublishCode == null)
            {
                throw new NullReferenceException("new user cannot be created without publish code");
            }
            var securedPublishCode = PublishCodeEncrypter.GenerateSHA256Hash(entity.PublishCode);

            var entityId = DBConnection.Query <long>(InsertQuery, new { Username = entity.Username, PublishCode = securedPublishCode, IsDeleted = entity.IsDeleted, IsVip = entity.IsVip }).FirstOrDefault();

            entity.Id          = entityId;
            entity.PublishCode = null; // we don't want to return the publish code
            return(entity);
        }
Example #2
0
        //public T Get(long id)
        //{
        //    return DataManager.CreateInstance<T>().Get(id);
        //}

        public long GetUserIdByPublishCode(string code)
        {
            if (code != null)
            {
                string hashedCode = PublishCodeEncrypter.GenerateSHA256Hash(code);

                var  repo   = Server.Data.Managers.DataManager.GetDataManager().CreateInstance <Haiku>(hashedCode);
                long?userId = ((BaseRepository <Haiku>)repo).GetUserIdByPublishCode(hashedCode);



                if (userId != null & (IsAdminPublishCode(hashedCode) || userId > 0))
                {
                    return(userId.Value);
                }
            }

            throw new UnauthorizedAccessException("invalid publish code");
        }
Example #3
0
 public static bool IsAdminPublishCode(string code)
 {
     return(code != null && Server.Data.Constants.Constants.AdminKeys.Contains(PublishCodeEncrypter.GenerateSHA256Hash(code)));
 }