示例#1
0
        //todo remove from role if logcount for type == 0
        public ServiceResult Delete(VerificationEntry n, bool purge = false)
        {
            ServiceResult res = ServiceResponse.OK();

            if (n == null)
            {
                return(ServiceResponse.Error("No record sent."));
            }

            //if (!this.DataAccessAuthorized(n, "DELETE", false)) return ServiceResponse.Error("You are not authorized this action.");

            using (var context = new GreenWerxDbContext(this._connectionKey))
            {
                if (purge && context.Delete <VerificationEntry>((VerificationEntry)n) == 0)
                {
                    return(ServiceResponse.Error("Failed to delete verification"));
                }

                //get the VerificationEntry from the table with all the data so when its updated it still contains the same data.
                res = this.Get(n.UUID);
                if (res.Code != 200)
                {
                    return(res);
                }

                n.Deleted = true;
                if (context.Update <VerificationEntry>((VerificationEntry)n) == 0)
                {
                    return(ServiceResponse.Error("Failed to delete verification. "));
                }
            }
            return(res);
        }
        public ServiceResult Delete(VerificationEntry s)
        {
            if (s == null || string.IsNullOrWhiteSpace(s.UUID))
            {
                return(ServiceResponse.Error("Invalid account was sent."));
            }

            VerificationManager verificationManager = new VerificationManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(verificationManager.Delete(s));
        }
示例#3
0
 public ActionResult Create(VerificationEntry entity)
 {
     if (ModelState.IsValid)
     {
         using (IUnitOfWork uow = uowFactory.Create()) {
             repository.Add(entity);
             uow.Save();
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(View());
     }
 }
示例#4
0
        public ServiceResult Update(VerificationEntry n)
        {
            if (n == null)
            {
                return(ServiceResponse.Error("Invalid verification data."));
            }

            //   if (!this.DataAccessAuthorized(n, "PATCH", false)) return ServiceResponse.Error("You are not authorized this action.");

            using (var context = new GreenWerxDbContext(this._connectionKey))
            {
                if (context.Update <VerificationEntry>((VerificationEntry)n) > 0)
                {
                    return(ServiceResponse.OK());
                }
            }
            return(ServiceResponse.Error("System error, VerificationEntry was not updated."));
        }
        public ServiceResult Delete(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("Invalid id was sent."));
            }

            VerificationManager verificationManager = new VerificationManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var res = verificationManager.Get(uuid);

            if (res.Code != 200)
            {
                return(res);
            }

            VerificationEntry fa = (VerificationEntry)res.Result;

            return(verificationManager.Delete(fa));
        }
示例#6
0
 public ActionResult Edit(VerificationEntry entity)
 {
     if (ModelState.IsValid)
     {
         using (IUnitOfWork uow = uowFactory.Create()) {
             VerificationEntry original = repository.All().Single(x => x.Id == entity.Id);
             original.Id                   = entity.Id;
             original.DateVerified         = entity.DateVerified;
             original.DigitalCode          = entity.DigitalCode;
             original.Image                = entity.Image;
             original.IsManualVerification = entity.IsManualVerification;
             original.AssetId              = entity.AssetId;
             uow.Save();
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(View());
     }
 }
示例#7
0
        //todo add to role if not already in it
        public ServiceResult Insert(VerificationEntry s)
        {
            var CurrentUser = this.GetUser(SessionKey);

            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            s.VerifierAccountUUID = CurrentUser.AccountUUID;
            s.VerifierUUID        = CurrentUser.UUID;
            s.VerificationDate    = DateTime.UtcNow;
            s.VerifierProfileUUID = this.GetProfileUUID(this.SessionKey);
            GreenWerx.Models.Membership.Profile verifierProfile = null;
            //todo check if set, if not use profile -> locationUUID
            if (string.IsNullOrWhiteSpace(s.VerifierLocationUUID))
            {
                ProfileManager profileManager = new ProfileManager(this._connectionKey, this.SessionKey);
                var            res            = profileManager.Get(s.VerifierProfileUUID);
                try
                {
                    if (res.Code == 200)
                    {
                        verifierProfile        = (GreenWerx.Models.Membership.Profile)res.Result;
                        s.VerifierLocationUUID = verifierProfile.LocationUUID;
                    }
                }
                catch
                {//not that important.
                }
            }

            var vcts = GetVerificationEntries(s.RecipientProfileUUID);
            //one user can do multiple adds. so make it that they can only verify every 90 days.
            var tmp = GetVerificationEntries(s.RecipientProfileUUID)
                      .FirstOrDefault(w => w.VerifierUUID == CurrentUser.UUID &&
                                      w.VerificationType.EqualsIgnoreCase(s.VerificationType) &&
                                      w.VerificationDate.AddDays(-90) < DateTime.UtcNow
                                      );//

            if (tmp != null)
            {
                return(ServiceResponse.Error("You may only verify every ninety days."));
            }

            RoleManager rm       = new RoleManager(this._connectionKey, CurrentUser);
            var         userRole = rm.GetRolesForUser(CurrentUser.UUID, CurrentUser.AccountUUID)
                                   .Where(w => w.Category.EqualsIgnoreCase("member"))
                                   .OrderByDescending(o => o.RoleWeight).FirstOrDefault();

            if (userRole == null)
            {
                return(ServiceResponse.Error("You must be assigned a role to verify."));
            }

            s.VerifierRoleUUID = userRole.UUID;

            //verificationType
            s.Weight = userRole.Weight; //<== role.Category of verifying user
            var relationshipRole = rm.GetRoles(CurrentUser.AccountUUID)
                                   .FirstOrDefault(w => w.CategoryRoleName.EqualsIgnoreCase(verifierProfile.RelationshipStatus) &&
                                                   w.Category.EqualsIgnoreCase("member"));

            s.Multiplier = relationshipRole.Weight;// <== of verifying user verifierProfile.RelationshipStatus
            var verTypeRole = rm.GetRoles(CurrentUser.AccountUUID).FirstOrDefault(w => w.Category.EqualsIgnoreCase("verified") &&
                                                                                  w.CategoryRoleName.EqualsIgnoreCase(s.VerificationType));

            //Category CategoryRoleName
            //verified critical user
            //verified    ambassador
            //verified    geolocation
            //verified    photo submission
            //verified other member
            s.VerificationTypeMultiplier = verTypeRole.Weight;
            s.Points = ((s.VerificationTypeMultiplier) + s.Weight) * s.Multiplier;

            string destinationRoleUUID = verTypeRole.UUID;// "verification role"; //TODO get the uuid for the verification role

            using (var context = new GreenWerxDbContext(this._connectionKey))
            {
                //todo add RecipientMemberRoleUUID //this is the member role (UsersInRoles) the user ended kup in due to the verification.
                //  create default roles fore verification

                //todo make this a transacion and add to verification role
                var ur = context.GetAll <UserRole>().Any(rpw => rpw.ReferenceUUID == s.RecipientUUID &&
                                                         rpw.AccountUUID == s.RecipientAccountUUID &&
                                                         rpw.RoleUUID == destinationRoleUUID);

                if (ur == false) // if not in role already
                {                // add to role..
                  //var role = context.GetAll<Role>()
                  //                    .FirstOrDefault(w => w.AccountUUID == s.RecipientAccountUUID &&
                  //                    w.Category.EqualsIgnoreCase("verified") &&
                  //                    w.CategoryRoleName.EqualsIgnoreCase(s.VerificationType)
                  //                    );

                    var guid             = Guid.NewGuid().ToString("N");
                    var userVerifiedRole = new UserRole()
                    {
                        GUUID         = guid,
                        UUID          = guid,
                        AccountUUID   = s.RecipientAccountUUID,
                        Action        = "get",
                        Active        = true,
                        AppType       = "web",
                        CreatedBy     = s.VerifierUUID,
                        DateCreated   = DateTime.UtcNow,
                        Deleted       = false,
                        EndDate       = DateTime.UtcNow.AddDays(90),
                        Name          = verTypeRole.Name,
                        ReferenceUUID = s.RecipientUUID,
                        ReferenceType = "User",
                        UUIDType      = "UserRole",
                        RoleOperation = verTypeRole.RoleOperation,
                        RoleWeight    = verTypeRole.RoleWeight,
                        RoleUUID      = verTypeRole.UUID,
                        Image         = verTypeRole.Image,
                        StartDate     = DateTime.UtcNow,
                    };
                    context.Insert <UserRole>(userVerifiedRole);

                    guid = Guid.NewGuid().ToString("N");
                    var profileRole = new UserRole()
                    {
                        GUUID         = guid,
                        UUID          = guid,
                        AccountUUID   = s.RecipientAccountUUID,
                        Action        = "get",
                        Active        = true,
                        AppType       = "web",
                        CreatedBy     = s.VerifierUUID,
                        DateCreated   = DateTime.UtcNow,
                        Deleted       = false,
                        EndDate       = DateTime.UtcNow.AddDays(90),
                        Name          = verTypeRole.Name,
                        ReferenceUUID = s.RecipientProfileUUID,
                        ReferenceType = "Profile",
                        UUIDType      = "UserRole",
                        RoleOperation = verTypeRole.RoleOperation,
                        RoleWeight    = verTypeRole.RoleWeight,
                        RoleUUID      = verTypeRole.UUID,
                        Image         = verTypeRole.Image,
                        StartDate     = DateTime.UtcNow,
                    };
                    context.Insert <UserRole>(profileRole);
                }

                if (context.Insert <VerificationEntry>(s))
                {
                    return(ServiceResponse.OK("", s));
                }
            }
            return(ServiceResponse.Error("An error occurred inserting verification."));
        }
        public ServiceResult Insert(VerificationEntry s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid verification sent to server."));
            }

            VerificationManager verificationManager = new VerificationManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            NetworkHelper network = new NetworkHelper();

            s.VerifierIP = network.GetClientIpAddress(this.Request);
            var res = verificationManager.Insert(s);

            if (res.Code != 200)
            {
                return(res);
            }

            // to do update verifications cache in profile class
            //Task.Run(async () =>
            //{
            //
            //profileManager.UpdateCache();
            //}

            return(res);

            //UserSession us = SessionManager.GetSession(authToken);
            //if (us == null)
            //    return ServiceResponse.Error("You must be logged in to access this function.");

            //if (string.IsNullOrWhiteSpace(us.UserData))
            //    return ServiceResponse.Error("Couldn't retrieve user data.");

            //if (CurrentUser == null)
            //    return ServiceResponse.Error("You must be logged in to access this function.");

            //s.VerifierAccountUUID = CurrentUser.AccountUUID;
            //s.VerifierUUID = CurrentUser.UUID;
            //s.VerificationDate = DateTime.UtcNow;
            //s.VerifierProfileUUID = this.GetProfileUUID(authToken);
            //GreenWerx.Models.Membership.Profile verifierProfile = null;
            ////todo check if set, if not use profile -> locationUUID
            //if (string.IsNullOrWhiteSpace(s.VerifierLocationUUID)) {
            //    ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            //    var res = profileManager.Get(s.VerifierProfileUUID);
            //    try
            //    {
            //        if (res.Code == 200)
            //        {
            //            verifierProfile = (GreenWerx.Models.Membership.Profile)res.Result;
            //            s.VerifierLocationUUID = verifierProfile.LocationUUID;
            //        }
            //    } catch
            //    {//not that important.
            //    }
            //}

            //var vcts = verificationManager.GetVerificationEntries(s.RecipientProfileUUID);

            //var tmp = verificationManager.GetVerificationEntries(s.RecipientProfileUUID)
            //    .FirstOrDefault(w => w.VerifierUUID == CurrentUser.UUID &&
            //         w.VerificationType.EqualsIgnoreCase(s.VerificationType)
            //          && w.VerificationDate.AddDays(-90) < DateTime.UtcNow
            //        );//
            //if (   tmp != null    )
            //    return ServiceResponse.Error("You may only verify every ninety days.");

            //RoleManager rm = new RoleManager(Globals.DBConnectionKey, CurrentUser);
            //var userRole = rm.GetRolesForUser(CurrentUser.UUID, CurrentUser.AccountUUID)
            //                    .Where(w => w.Category.EqualsIgnoreCase("member"))
            //                    .OrderByDescending(o => o.RoleWeight).FirstOrDefault();

            //if(userRole == null)
            //    return ServiceResponse.Error("You must be assigned a role to verify.");

            //s.VerifierRoleUUID = userRole.UUID;

            ////verificationType
            //s.Weight  =  userRole.Weight; //<== role.Category of verifying user
            //var relationshipRole =  rm.GetRoles(SystemFlag.Default.Account).FirstOrDefault(w => w.CategoryRoleName.EqualsIgnoreCase(verifierProfile.RelationshipStatus));
            //s.Multiplier = relationshipRole.Weight;// <== of verifying user verifierProfile.RelationshipStatus
            //var verTypeRole = rm.GetRoles(SystemFlag.Default.Account).FirstOrDefault(w => w.Category.EqualsIgnoreCase("verified")
            //                                                    && w.CategoryRoleName.EqualsIgnoreCase(s.VerificationType));
            ////Category CategoryRoleName
            ////verified critical user
            ////verified    ambassador
            ////verified    geolocation
            ////verified    photo submission
            ////verified other member
            //s.VerificationTypeMultiplier = verTypeRole.Weight;
            //s.Points = ((s.VerificationTypeMultiplier) + s.Weight) * s.Multiplier;

            //  return verificationManager.Insert(s);
        }