示例#1
0
        public async Task <bool> Register(UserProfile userprofile)
        {
            try
            {
                var userProfileRepo = new UserProfileRepository();
                await userProfileRepo.CreateSync(userprofile);

                var userId = userprofile.Id.ToString();
                if (!string.IsNullOrEmpty(userId))
                {
                    var code  = userId.Substring(userId.Length - 6, 6);
                    var badge = new Badge
                    {
                        User = userprofile.Username,
                        Code = code,
                        IsAddressVerified        = false,
                        IsDriversLicenseVerified = false,
                        IsPhoneVerified          = false,
                        IsVehicleVerified        = false
                    };

                    var badgeRepo = new BadgeRepository();
                    await badgeRepo.CreateSync(badge);

                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#2
0
        public async Task<bool> Register(UserProfile userprofile)
        {
            try
            {
                var userProfileRepo = new UserProfileRepository();
                await userProfileRepo.CreateSync(userprofile);

                var userId = userprofile.Id.ToString();
                if (!string.IsNullOrEmpty(userId))
                {
                    var code = userId.Substring(userId.Length - 6, 6);
                    var badge = new Badge
                    {
                        User = userprofile.Username,
                        Code = code,
                        IsAddressVerified = false,
                        IsDriversLicenseVerified = false,
                        IsPhoneVerified = false,
                        IsVehicleVerified = false
                    };

                    var badgeRepo = new BadgeRepository();
                    await badgeRepo.CreateSync(badge);
                    return true;
                }
                return false;
            }
            catch(Exception ex)
            {
                return false;
            }
        }
示例#3
0
        public async Task <ActionResult> LoginFacebook(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { success = false, responseText = "Invalid parameters" }, JsonRequestBehavior.AllowGet));
            }

            var user = UserManager.Users.Where(n => n.UserName == model.UserName);

            if (!user.Any())
            {
                var createResult = await UserManager.CreateAsync(new ApplicationUser { UserName = model.UserName }, "socialMedia");

                var userProfileRepo = new UserProfileRepository();
                userProfileRepo.CreateSync(new Data.Model.UserProfile
                {
                    Username       = model.UserName,
                    Password       = "******",
                    Email          = model.Email,
                    isFacebookUser = false,
                    DateRegistered = DateTime.UtcNow
                });
                UserManager.Create(new ApplicationUser {
                    UserName = model.UserName
                }, model.Password);
            }


            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, "socialMedia", model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(Json(new { success = true, responseText = "Added." }, JsonRequestBehavior.AllowGet));

                break;
                //    return RedirectToLocal(returnUrl);
                ////case SignInStatus.LockedOut:
                //    return View("Lockout");
                //case SignInStatus.RequiresVerification:
                //    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                //case SignInStatus.Failure:
                //default:
                //    ModelState.AddModelError("", "Invalid login attempt.");
                //    return View(model);
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { success = false, responseText = "Invalid parameters" }, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public async Task<ActionResult> LoginFacebook(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json(new { success = false, responseText = "Invalid parameters" }, JsonRequestBehavior.AllowGet);
            }

            var user = UserManager.Users.Where(n => n.UserName == model.UserName);
            if (!user.Any())
            {
                var createResult = await UserManager.CreateAsync(new ApplicationUser { UserName = model.UserName }, "socialMedia");

                var userProfileRepo = new UserProfileRepository();
                userProfileRepo.CreateSync(new Data.Model.UserProfile
                {
                    Username = model.UserName,
                    Password = "******",
                    Email = model.Email,
                    isFacebookUser = false,
                    DateRegistered = DateTime.UtcNow
                });
                UserManager.Create(new ApplicationUser { UserName = model.UserName }, model.Password);
            }


            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, "socialMedia", model.RememberMe, shouldLockout: false);
            switch (result)
            {
                    
                case SignInStatus.Success:
                    return Json(new { success = true, responseText = "Added." }, JsonRequestBehavior.AllowGet);
                    break;
                //    return RedirectToLocal(returnUrl);
                ////case SignInStatus.LockedOut:
                //    return View("Lockout");
                //case SignInStatus.RequiresVerification:
                //    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                //case SignInStatus.Failure:
                //default:
                //    ModelState.AddModelError("", "Invalid login attempt.");
                //    return View(model);
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return Json(new { success = false, responseText = "Invalid parameters" }, JsonRequestBehavior.AllowGet);
        }