Ejemplo n.º 1
0
 public void CopyFromUserIncludeCredentials(User user)
 {
     CopyFromUser(user);
     if(user.Credential != null)
         Credentials = new CredentialsLite
         {
             Email = user.Credential.Email,
             Username = user.Credential.Username
         };
 }
Ejemplo n.º 2
0
 public new void CopyFromUser(User user)
 {
     base.CopyFromUser(user);
     if (user.Facebook != null)
     {
         this.Twitter = user.Twitter;
         // set clear the sensitive data as lite objects travel to client.
         this.Twitter.TwitterAccessToken = null;
     }
 }
Ejemplo n.º 3
0
        // The people who have followed this user.
        public void CopyFromUser(User user)
        {
            this.DisplayName = user.DisplayName;
            this.Photo = user.Photo;
            this.RoleId = user.RoleId;
            this.UserId = user.UserId;
            this.Address = user.Address;
            if (string.IsNullOrWhiteSpace(user.ZenmateId) == false)
                this.ZenDeskUserId = long.Parse(user.ZenmateId);

            if (user.ZenmateTicketId != null)
                ZenDeskTicketId = (long)user.ZenmateTicketId.Value;
        }
Ejemplo n.º 4
0
 public WebCookieLite(User user, Uri refferer)
 {
     if (user == null || user.Credential == null)
         throw new MissingFieldException("User and its Credential cannot be null while initializing cookie.");
     Email = user.Credential.Email;
     Token = user.Credential.WebSecurityToken;
     //if (user.RoleId == "1")
     //    HomeUrl = "/users/";
     //else
     if (user.RoleId == "3")
         HomeUrl = "/admin/";
     else
     {
         if (refferer == null || string.IsNullOrWhiteSpace(refferer.AbsoluteUri))
             HomeUrl = "/users";
         else
             HomeUrl = refferer.AbsoluteUri;
     }
 }
Ejemplo n.º 5
0
        private long? CreateUser(User user, string email, string type)
        {
            if (string.IsNullOrWhiteSpace(type))
                throw new MissingFieldException("User's type cannot be empty for zendesk.");

            string encodedEmail = HttpContext.Current.Server.UrlEncode(email);
            ZendeskApi_v2.ZendeskApi api = new ZendeskApi_v2.ZendeskApi(_ZenDeskPath, _ZenDeskUser,
                    _ZenDeskApiKey, _ZenDeskLocal);

            // Double check if user is already created on zendesk...
            ZendeskApi_v2.Models.Users.GroupUserResponse responseOld =
                                    api.Users.SearchByEmail(encodedEmail);
            if (responseOld != null && responseOld.Count > 0)
                return responseOld.Users[0].Id;

            // The user is not previously registered with zen. Lets register now.
            ZendeskApi_v2.Models.Users.User zenUser = new ZendeskApi_v2.Models.Users.User();
            zenUser.Active = true;
            zenUser.Alias = user.DisplayName;
            zenUser.Details = type;
            //zenUser.Photo = new ZendeskApi_v2.Models.Users.Photo { ContentUrl = user.Photo };
            zenUser.Email = user.Credential.Email;
            zenUser.Name = user.DisplayName;
            zenUser.ExternalId = user.UserId;
            zenUser.Verified = true;
            zenUser.Role = type.Trim().ToLower();
            ZendeskApi_v2.Models.Users.IndividualUserResponse response = api.Users.CreateUser(zenUser);
            if (response.User == null)
                return null;
            return response.User.Id;
        }
Ejemplo n.º 6
0
 public long? RegisterEndUser(User user, string email)
 {
     return CreateUser(user, email, "End-User");
 }
Ejemplo n.º 7
0
 public long? RegisterAgent(User user, string email)
 {
     return CreateUser(user, email, "Agent");
 }
Ejemplo n.º 8
0
        public User LoginWithFacebookWeb(FbCredentials credentials)
        {
            if (credentials == null)
                throw new ParamMissingException("Missing credentials.");

            User user = Repository.Single<User>(c => c.Deleted == false
               && c.Facebook.FbId.Equals(credentials.FbId)
               , "Credential", "Facebook");

            if (user != null)
            {
                // update the Facebook access token
                user.Facebook.FbAccessToken = credentials.FbAccessToken;
                user.Credential.WebSecurityToken = Guid.NewGuid().ToString();
                Repository.Save();
                return user;
            }
            else
            {
                // check if email exists
                User EmailUser = Repository.Single<User>(c => c.Deleted == false
                   && c.Credential.Email.Equals(credentials.FbEmail)
                   , "Credential", "Facebook");

                if (EmailUser != null)
                {
                    if (EmailUser.Facebook == null)
                    {
                        EmailUser.Facebook = new FbUser();

                        // update the Facebook ID
                        EmailUser.Facebook.FbId = credentials.FbId;
                        // update the Facebook access token
                        EmailUser.Facebook.FbAccessToken = credentials.FbAccessToken;
                        EmailUser.Credential.WebSecurityToken = Guid.NewGuid().ToString();
                        Repository.Save();
                    }
                    else
                    {
                        return null;
                    }
                    return EmailUser;
                }
                else
                {
                    // create new user
                    User NewUser = new User();
                    NewUser.Facebook = new FbUser();

                    NewUser.Credential = new Credential();
                    NewUser.Credential.Email = credentials.FbEmail;
                    NewUser.Credential.Username = credentials.FbEmail;
                    NewUser.Credential.WebSecurityToken = Guid.NewGuid().ToString();

                    DateTime currentTime = DateTime.UtcNow;

                    NewUser.Facebook.FbEmail = credentials.FbEmail;
                    NewUser.Facebook.FbId = credentials.FbId;
                    NewUser.Facebook.FbAccessToken = credentials.FbAccessToken;
                    NewUser.UserId = Guid.NewGuid().ToString();
                    NewUser.Deleted = false;
                    NewUser.CreatedAt = currentTime;
                    NewUser.LastModified = currentTime;

                   // NewUser.Role = new Role();
                   // NewUser.Role.RoleId = "1";
                    NewUser.RoleId = "1";

                    NewUser.Credential.CredentialId = Guid.NewGuid().ToString();
                    NewUser.Credential.Deleted = false;
                    NewUser.Credential.LastModified = currentTime;
                    NewUser.Credential.TokenExpiry = DateTime.MaxValue;
                    NewUser.Credential.CreatedAt = currentTime;
                    NewUser.Credential.LastModified = currentTime;

                    NewUser.Credential.SecurityToken = Guid.NewGuid().ToString();
                    NewUser.Credential.LastModified = DateTime.UtcNow;
                    NewUser.Credential.TokenExpiry = DateTime.MaxValue;

                    NewUser.CredentialId = NewUser.Credential.CredentialId;

                    Repository.Add<User>(NewUser);
                    Repository.Save();
                    return NewUser;
                }

            }
        }
Ejemplo n.º 9
0
        public User AddFacebookUser(FbUserLite liteUser)
        {
            if (liteUser.Facebook == null || Extensions.ExtensionMethods.IsEmptyOrSpace(liteUser.Facebook.FbId))
                throw new ParamMissingException("Facebook ID cannot be empty.");
            else
                if (FbIdExists(liteUser.Facebook.FbId))
                    throw new AlreadyExistsException("Facebook ID already registered.");

            if (EmailExists(liteUser.Credentials.Email))
                throw new AlreadyExistsException("Email already registered.");

            if (liteUser == null || liteUser.Credentials == null)
                throw new ParamMissingException("Missing credentials fields.");

            if (string.IsNullOrEmpty(liteUser.Credentials.Email))
                throw new InvalidValueException("Email cannot be empty.");

            //if (string.IsNullOrEmpty(liteUser.Credentials.Password))
            //    throw new InvalidValueException("Password cannot be empty.");

            if (Extensions.ExtensionMethods.IsValidEmail(liteUser.Credentials.Email) == false)
                throw new InvalidValueException("Invalid email provided.");

            Role role = Repository.Single<Role>(x => x.RoleId.Equals(liteUser.RoleId) && x.Deleted == false);
            if (role == null)
                throw new InvalidValueException("Role Id is invalid.");
            if (UsernameExists(liteUser.Credentials.Username))
                throw new AlreadyExistsException("Username already exists.");

            DateTime currentTime = DateTime.UtcNow;
            User user = new User
            {
                CreatedAt = currentTime,
                Credential = new Credential
                {
                    CreatedAt = currentTime,
                    CredentialId = Guid.NewGuid().ToString(),
                    Deleted = false,
                    Devices = new List<UserDevice>(0),
                    Email = liteUser.Credentials.Email,
                    LastModified = currentTime,
                    Password = liteUser.Credentials.Password, // Should already be hashed in calling function
                    WebSecurityToken = Guid.NewGuid().ToString(),
                    SecurityToken = Guid.NewGuid().ToString(),
                    TokenExpiry = DateTime.MaxValue,
                    Username = liteUser.Credentials.Username,
                },
                Deleted = false,
                Facebook = liteUser.Facebook,
                LastModified = currentTime,
                Photo = liteUser.Photo,
                RoleId = liteUser.RoleId,
                Address = liteUser.Address,
                UserId = Guid.NewGuid().ToString(),
                DisplayName = string.IsNullOrEmpty(liteUser.DisplayName) ?
                                        string.IsNullOrEmpty(liteUser.Facebook.FbUsername) ?
                                                liteUser.Credentials.Username : liteUser.Facebook.FbUsername
                                        : liteUser.DisplayName.Trim()
            };

            user.CredentialId = user.Credential.CredentialId;

            Repository.Add<User>(user);
            Repository.Save();
            return user;
        }
Ejemplo n.º 10
0
 public UserLite(User user)
 {
     CopyFromUser(user);
 }
Ejemplo n.º 11
0
        public string EditBuyer(string DisplayName, string id, User User)
        {
            //return _adminSeller.EditSeller(dislayName, username, FullStreetAddress, ReopAddDate, Beds, email, PropertyStatus, id).ToString();
            _adminSeller.EditBuyer(DisplayName, id);

            return "";
        }