Пример #1
0
        public IHttpActionResult Loginreturn([FromUri] FanapModel fanapModel)
        {
            try
            {
                var            res    = new UserRegisterModel();
                var            fModel = _fanapManager.GetFanapUserInfo(fanapModel);
                IdentityResult result;
                var            userObj = new ApplicationUser()
                {
                    UserName = fModel.UserName, Name = fModel.Name, Family = fModel.Family, MobileConfirmed = false, Code = "Fanap"
                };
                //var userObj = new ApplicationUser() { Name = model.Name, Family = model.Family, Gender = model.Gender, UserName = model.Mobile,Code=model.Code, MobileConfirmed = false };
                var user    = AppUserManager.FindByName(fModel.UserName);
                var newPass = System.Web.Security.Membership.GeneratePassword(16, 0);
                if (user == null)
                {
                    result = AppUserManager.Create(userObj, newPass);
                    if (result.Succeeded)
                    {
                        user = AppUserManager.FindByName(fModel.UserName);
                        AppUserManager.AddToRole(user.Id, UserRoles.MobileDriver.ToString());
                        _fanapManager.SaveFanapUser(user.Id, fModel.UserId);
                        res.Mobile   = fModel.UserName;
                        res.Password = newPass;
                        return(Json(_responseProvider.GenerateResponse(res, "userpass")));

                        /*var url = "http://exitthisactivity";
                         * var response = Request.CreateResponse(HttpStatusCode.Moved);
                         * response.Headers.Location = new Uri(url);
                         * return response;*/
                    }
                }
                else
                {
                    _fanapManager.SaveFanapUser(user.Id, fModel.UserId);
                    result = AppUserManager.RemovePassword(user.Id);
                    if (result.Succeeded)
                    {
                        result = AppUserManager.AddPassword(user.Id, newPass);
                        if (result.Succeeded)
                        {
                            bool isUserRegistered = !string.IsNullOrEmpty(user.Name);
                            user.MobileConfirmed = true;
                            AppUserManager.Update(user);
                            res.Mobile   = fModel.UserName;
                            res.Password = newPass;
                            return(Json(_responseProvider.GenerateResponse(res, "userpass")));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logmanager.Log(Tag, "Loginreturn", e.Message);
            }
            return(Json(_responseProvider.GenerateUnknownErrorResponse()));
        }
Пример #2
0
        public UserModel GetFanapUserInfo(FanapModel fanapModel)
        {
            var userInfomodel = new UserModel();
            var fanapService  = new FanapService();
            var userInfo      = new FanapUserInfo();

            using (var dataModel = new MibarimEntities())
            {
                var cont = fanapService.GetAuthenticationToken(fanapModel.Code);
                if (cont.access_token != null)
                {
                    userInfo = fanapService.GetFanapUser(cont.access_token);
                    if (userInfo != null)
                    {
                        var fanap = new Fanap();
                        fanap.userId             = 1;
                        fanap.authorization_code = fanapModel.Code;
                        fanap.access_token       = cont.access_token;
                        fanap.refresh_token      = cont.refresh_token;
                        fanap.nickName           = userInfo.nickName;
                        fanap.birthDate          = userInfo.birthDate;
                        fanap.fuserId            = userInfo.userId;
                        userInfomodel.UserId     = userInfo.userId;
                        userInfomodel.Name       = userInfo.firstName;
                        userInfomodel.Family     = userInfo.lastName;
                        userInfomodel.UserId     = userInfo.userId;
                        userInfomodel.UserName   = userInfo.cellphoneNumber;
                        userInfomodel.Email      = userInfo.email;
                        fanap.score = userInfo.score.ToString();
                        dataModel.Fanaps.Add(fanap);
                        dataModel.SaveChanges();
                        var business = fanapService.getBusiness();
                        fanapService.FollowBusiness(cont.access_token, business.result.id);
                        return(userInfomodel);
                    }
                }
            }

            return(userInfomodel);
        }