예제 #1
0
        public async Task <JsonResult> New()
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }
            var result = SessionWrapper.Get <LiveLoginResult>("LiveConnectResult");

            if (result != null && result.Status == LiveConnectSessionStatus.Connected)
            {
                var profileDetails = SessionWrapper.Get <ProfileDetails>("ProfileDetails");

                // While creating the user, IsSubscribed to be true always.
                profileDetails.IsSubscribed = true;

                // When creating the user, by default the user type will be of regular.
                profileDetails.UserType = UserTypes.Regular;

                profileDetails.ID = ProfileService.CreateProfile(profileDetails);
                SessionWrapper.Set("CurrentUserID", profileDetails.ID);
                CreateDefaultUserCommunity(profileDetails.ID);

                // Send New user notification.
                _notificationService.NotifyNewEntityRequest(profileDetails, HttpContext.Request.Url.GetServerLink());
                return(new JsonResult {
                    Data = profileDetails
                });
            }
            return(Json("error: User not logged in"));
        }
예제 #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    UserManager.AddToRole(user.Id, "User");
                    var service = new ProfileService(Guid.Parse(user.Id));
                    service.CreateProfile();
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Edit", "Profile", new { Id = Guid.Parse(user.Id) }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #3
0
        public ActionResult JsonFacebook(FacebookProfileModel model)
        {
            if (ModelState.IsValid)
            {
                KatushaMembershipCreateStatus createStatus;
                var tmpGuid = Guid.NewGuid().ToString("N");
                var user    = UserService.CreateUser(tmpGuid, "tEmpPassword", model.Email, null, null, true, null, out createStatus);
                if (createStatus == KatushaMembershipCreateStatus.Success)
                {
                    var profile = Mapper.Map <Profile>(model);
                    profile.UserId = user.Id;
                    profile.Guid   = user.Guid;

                    ProfileService.CreateProfile(profile);
                    user.FacebookUid = model.FacebookId;
                    user.UserRole    = (long)UserRole.Normal;
                    UserService.UpdateUser(user);
                    FormsAuthentication.SetAuthCookie(tmpGuid, createPersistentCookie: false);
                    return(Json(new { success = true }));
                }
                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }
            var errors = GetErrorsFromModelState();

            return(Json(new { errors }));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Birthday,PhotoUrl")] Profile profile, HttpPostedFileBase binaryFile)
        {
            if (ModelState.IsValid)
            {
                if (binaryFile != null)
                {
                    var photo = new Photo
                    {
                        ContainerName = "profilepictures",
                        FileName      = binaryFile.FileName,
                        BinaryContent = binaryFile.InputStream,
                        ContentType   = binaryFile.ContentType
                    };
                    string newPhotoUrl = _fileService.UploadPhoto(photo);
                    profile.PhotoUrl = newPhotoUrl;
                }
                profile.Id = Guid.Parse(Session["profileId"].ToString());
                //db.Profiles.Add(profile);
                //db.SaveChanges();
                _profileService.CreateProfile(profile);
                return(RedirectToAction("Details", new { @id = Session["profileId"].ToString() }));
            }

            return(View(profile));
        }
예제 #5
0
        public int?CreateProfile()
        {
            var createResult = _profileService.CreateProfile(GenerateProfileModelObject());

            ValidateSuccess(createResult, nameof(CreateProfile));

            return(createResult.Value);
        }
        public async Task <IActionResult> Post([FromBody] Profile profile)
        {
            var res = await _service.CreateProfile(profile);

            if (res == null)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
예제 #7
0
        public IHttpActionResult PostProfile(Profile profile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Profiles.Add(profile);

            _profileService.CreateProfile(profile);

            return(CreatedAtRoute("DefaultApi", new { id = profile.Id }, profile));
        }
예제 #8
0
        public async Task <ActionResult> CreateProfile([FromBody] Profils profils)
        {
            try
            {
                var result = await _profilService.CreateProfile(profils);

                return(Ok(result));
            }
            catch (Exception e)
            {
                var msg = $"Error When Create Profile. {e.Message}";
                return(StatusCode(500, msg));
            }
        }
        public void CreateProfil_UserIdExists_ThrowsInvalidProfile()
        {
            // Arrange
            var profileRepository = new Mock <IProfileRepository>();
            var client            = new Mock <IClient>();

            profileRepository.Setup(m => m.UserIdExists(It.IsAny <string>())).ReturnsAsync(true);

            var profileService = new ProfileService(profileRepository.Object, client.Object);

            // Act
            // Assert
            Assert.ThrowsAsync <InvalidProfile>(() => profileService.CreateProfile(new Profile()));
        }
        public void CreateProfil_CreateProfile_ReturnsUserProfile()
        {
            // Arrange
            var profileRepository = new Mock <IProfileRepository>();
            var client            = new Mock <IClient>();

            profileRepository.Setup(m => m.UserIdExists(It.IsAny <string>())).ReturnsAsync(true);
            profileRepository.Setup(m => m.Create(It.IsAny <Profile>())).ReturnsAsync(new Profile());

            var profileService = new ProfileService(profileRepository.Object, client.Object);

            // Act
            var actual = profileService.CreateProfile(new Profile());

            // Assert
            Assert.NotNull(actual);
        }
예제 #11
0
        public void CreateProfileTest()
        {
            TestInfo         testInfo = GetDefaultTestInfo();
            IProfileProvider profileProviderCustom = ProfileProviderMoqs.GetImplemented(testInfo);
            IProfileService  testObject            = new ProfileService(profileProviderCustom, _userManager, _imageService, _mapper);

            var profile = new ProfileDto()
            {
                Id       = 1,
                UserName = Guid.NewGuid().ToString(),
                FullName = Guid.NewGuid().ToString()
            };

            Assert.DoesNotThrow(() => testObject.CreateProfile(profile));

            profileProviderCustom.Received().Create(Arg.Any <UserProfile>());
        }
예제 #12
0
        public async void ProfileControllerCreateTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("Profiles")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                ProfileService TestService = new ProfileService(context);
                Profile        profile     = new Profile();
                profile.Username    = "******";
                profile.LocationZip = 98146;
                await TestService.CreateProfile(profile);

                var TestProfile = await TestService.GetProfile("James");

                Assert.Equal("James", TestProfile.Username);
            }
        }
        public async Task <bool> RegisterUser()
        {
            var profileDetails = await ValidateAuthentication();

            if (profileDetails == null)
            {
                var     svc        = new LiveIdAuth();
                dynamic jsonResult = svc.GetMeInfo(System.Web.HttpContext.Current.Request.Headers["LiveUserToken"]);
                profileDetails = new ProfileDetails(jsonResult);
                // While creating the user, IsSubscribed to be true always.
                profileDetails.IsSubscribed = true;

                // When creating the user, by default the user type will be of regular.
                profileDetails.UserType = UserTypes.Regular;
                profileDetails.ID       = ProfileService.CreateProfile(profileDetails);

                // This will used as the default community when user is uploading a new content.
                // This community will need to have the following details:
                var communityDetails = new CommunityDetails
                {
                    CommunityType = CommunityTypes.User,              // 1. This community type should be User
                    CreatedByID   = profileDetails.ID,                // 2. CreatedBy will be the new USER.
                    IsFeatured    = false,                            // 3. This community is not featured.
                    Name          = Resources.UserCommunityName,      // 4. Name should be NONE.
                    AccessTypeID  = (int)AccessType.Private,          // 5. Access type should be private.
                    CategoryID    = (int)CategoryType.GeneralInterest // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null.
                };

                // 7. Create the community
                _communityService.CreateCommunity(communityDetails);

                // Send New user notification.
                _notificationService.NotifyNewEntityRequest(profileDetails,
                                                            HttpContext.Request.Url.GetServerLink());
            }
            else
            {
                throw new WebFaultException <string>("User already registered", HttpStatusCode.BadRequest);
            }
            return(true);
        }
예제 #14
0
 private ActionResult _Register(RegisterModel model, ActionResult successResult, ActionResult failResult)
 {
     if (ModelState.IsValid)
     {
         var hasError = false;
         if (model.Photo == null || model.Photo.ContentLength <= 0)
         {
             ModelState.AddModelError("Photo", "You must add a photo");
             hasError = true;
         }
         if ((byte)model.Gender <= 0 || (byte)model.Gender > 2)
         {
             ModelState.AddModelError("gender2", "You must select a gender");
             hasError = true;
         }
         if (String.IsNullOrWhiteSpace(model.Location.CountryCode))
         {
             ModelState.AddModelError("Location.CountryName", "You must select a country");
             hasError = true;
         }
         if (!hasError)
         {
             KatushaMembershipCreateStatus createStatus;
             KatushaUser = UserService.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
             if (createStatus == KatushaMembershipCreateStatus.Success)
             {
                 var profile = Mapper.Map <Profile>(model);
                 profile.UserId = KatushaUser.Id;
                 profile.Guid   = KatushaUser.Guid;
                 ProfileService.CreateProfile(profile);
                 KatushaProfile = profile;
                 _photoService.AddPhoto(profile.Id, "", model.Photo);
                 FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                 return(successResult);
             }
             ModelState.AddModelError("", ErrorCodeToString(createStatus));
         }
     }
     return(failResult);
 }
        public async Task <String> insert()
        {
            var ms_wang = new Profile()
            {
                Username = "******",
                Groups   = new List <string>(),
                Friends  = new List <string>()
            };

            ms_wang.Groups.Add("family");
            var ms_yang = new Profile()
            {
                Username = "******",
                Groups   = new List <string>(),
                Friends  = new List <string>()
            };
            var ms_li = new Profile()
            {
                Username = "******",
                Groups   = new List <string>(),
                Friends  = new List <string>()
            };
            var ms_he = new Profile()
            {
                Username = "******",
                Groups   = new List <string>(),
                Friends  = new List <string>()
            };
            await profileservice.CreateProfile(ms_wang);

            await profileservice.CreateProfile(ms_yang);

            await profileservice.CreateProfile(ms_li);

            await profileservice.CreateProfile(ms_he);

            await profileservice.AddUserFriend("wang", "li");

            await groupservice.MakeFriend("wang", "li");

            await profileservice.AddUserFriend("wang", "yang");

            await groupservice.MakeFriend("wang", "yang");

            var group1 = new ChatGroup()
            {
                name           = "family",
                isFriend       = false,
                owner          = "wang",
                describe       = "wei are family",
                members        = new List <string>(),
                UserLatestRead = new Dictionary <string, ObjectId>(),
            };

            group1.UserLatestRead.Add("wang", ObjectId.GenerateNewId());
            group1.members.Add("wang");
            await groupservice.MakeGroup(group1);

            await profileservice.AddUserGroup("he", "family");

            await groupservice.AddGroup("he", "family");

            await profileservice.AddUserGroup("li", "family");

            await groupservice.AddGroup("li", "family");

            await userservice.InsertUser(new Models.User()
            {
                Username = "******", Password = "******"
            });

            await userservice.InsertUser(new Models.User()
            {
                Username = "******", Password = "******"
            });

            await userservice.InsertUser(new Models.User()
            {
                Username = "******", Password = "******"
            });

            await userservice.InsertUser(new Models.User()
            {
                Username = "******", Password = "******"
            });

            return("Ok");
        }
예제 #16
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            if (model.Role == "Parent")
            {
                var athleteUser = UserManager.FindByName(model.AthleteUsername);

                if (athleteUser != null)
                {
                    var user = new ApplicationUser()
                    {
                        UserName = model.Email, Email = model.Email
                    };

                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var result1            = UserManager.AddToRole(user.Id, "Parent");
                        var service            = new ProfileService(Guid.Parse(user.Id));
                        var modelCreateProfile = service.CreateProfile(new ProfileCreate {
                            UserID = Guid.Parse(user.Id), AthleteUsername = athleteUser.UserName
                        });
                        var connectAthlete = service.AddParentToAthlete(Guid.Parse(athleteUser.Id), user.UserName);
                    }
                    return(Ok());
                }
                return(BadRequest());
            }
            else
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //add role to user
                    if (model.Role == "Coach")
                    {
                        var result1            = UserManager.AddToRole(user.Id, "Coach");
                        var service            = new ProfileService(Guid.Parse(user.Id));
                        var modelCreateProfile = service.CreateProfile(new ProfileCreate {
                            UserID = Guid.Parse(user.Id)
                        });
                        return(Ok());
                    }

                    else if (model.Role == "Athlete")
                    {
                        var result1            = UserManager.AddToRole(user.Id, "Athlete");
                        var service            = new ProfileService(Guid.Parse(user.Id));
                        var modelCreateProfile = service.CreateProfile(new ProfileCreate {
                            UserID = Guid.Parse(user.Id)
                        });
                        return(Ok());
                    }

                    return(Ok());
                }
                return(GetErrorResult(result));
            }
        }
예제 #17
0
        public SessionData CreateProfile(ClientInformation clientInfo, ProfileDTO newProfile)
        {
            ProfileService profileService = new ProfileService(Session, null, Configuration, SecurityManager, PushNotificationService, EMailService);

            return(profileService.CreateProfile(clientInfo, newProfile));
        }
예제 #18
0
        public ActionResult <IEnumerable <bool> > CreateProfile([FromBody] Profile profile)
        {
            IProfileService profileService = new ProfileService();

            return(Ok(profileService.CreateProfile(profile)));
        }