示例#1
0
        public Task RemoveLoginAsync(AspNetUser user, UserLoginInfo login)
        {
            Debugger.Launch();
            this.ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (login == null)
            {
                throw new ArgumentNullException("login");
            }

            AspNetUserLogin userLogin = user.AspNetUserLogins.Where(o =>
            {
                if (!(o.LoginProvider == login.LoginProvider) || o.AspNetUser != (object)user)
                {
                    return(false);
                }
                return(o.ProviderKey == login.ProviderKey);
            }).SingleOrDefault();

            if (userLogin != null)
            {
                this.Context.Delete(userLogin);
            }

            return(Task.FromResult <int>(0));
        }
示例#2
0
        public void Create(AspNetUserLogin entity)
        {
            try
            {
                context.AspNetUserLogins.Add(entity);
                context.Entry(entity).State = EntityState.Added;
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
#if DEBUG
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                          ve.PropertyName,
                                          eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                          ve.ErrorMessage);
                    }
#endif
                }
                throw e;
            }
        }
示例#3
0
        public ActionResult DeleteConfirmed(string id)
        {
            AspNetUserLogin aspNetUserLogin = db.AspNetUserLogins.Find(id);

            db.AspNetUserLogins.Remove(aspNetUserLogin);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public static void UpdateAspNetUserLogin(AspNetUserLogin aspNetUserLogin)
 {
     using (DOAMEntities db = new DOAMEntities())
     {
         db.Entry(aspNetUserLogin).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
 public static void AddAspNetUserLogin(AspNetUserLogin aspNetUserLogin)
 {
     using (DOAMEntities db = new DOAMEntities())
     {
         db.AspNetUserLogins.Add(aspNetUserLogin);
         db.SaveChanges();
     }
 }
示例#6
0
 public ActionResult Edit([Bind(Include = "password,Email")] AspNetUserLogin aspNetUserLogin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetUserLogin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(aspNetUserLogin));
 }
 public ActionResult Edit([Bind(Include = "LoginProvider,ProviderKey,UserId")] AspNetUserLogin aspNetUserLogin)
 {
     if (ModelState.IsValid)
     {
         MyApp.Domain.UsersServices.AspNetUserLoginsService.UpdateAspNetUserLogin(aspNetUserLogin);
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(MyApp.Domain.UsersServices.UsersService.GetAspNetUsers(), "Id", "Email", aspNetUserLogin.UserId);
     return(View(aspNetUserLogin));
 }
示例#8
0
 public void Delete(AspNetUserLogin entity)
 {
     try
     {
         this.repository.Delete(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public ActionResult Edit([Bind(Include = "LoginProvider,ProviderKey,UserId")] AspNetUserLogin aspNetUserLogin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetUserLogin).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", aspNetUserLogin.UserId);
     return(View(aspNetUserLogin));
 }
示例#10
0
        public ActionResult Create([Bind(Include = "password,Email")] AspNetUserLogin aspNetUserLogin)
        {
            if (ModelState.IsValid)
            {
                db.AspNetUserLogins.Add(aspNetUserLogin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aspNetUserLogin));
        }
示例#11
0
 public AspNetUserLogin GetUserLogin(AspNetUserLogin userLogin)
 {
     return(_cacheManager.Get(
                string.Format(CachingKey.CommonMembershipUserServiceUserLoginByProviderKeyAndLoginProvider,
                              userLogin.ProviderKey, userLogin.LoginProvider), cacheTime,
                () =>
     {
         return _userLoginRepository.GetAll(p => p.LoginProvider == userLogin.LoginProvider &&
                                            p.ProviderKey == userLogin.ProviderKey).FirstOrDefault();
     }, cacheNull));
 }
示例#12
0
        public Task <AspNetUser> FindAsync(UserLoginInfo login)
        {
            this.ThrowIfDisposed();
            if (login == null)
            {
                throw new ArgumentNullException("login");
            }

            AspNetUserLogin UserLogin = this.Context.AspNetUserLogins.Where(o => o.LoginProvider == login.LoginProvider && o.ProviderKey == login.ProviderKey).FirstOrDefault();

            return(Task.FromResult(UserLogin != null ? UserLogin.AspNetUser : null));
        }
示例#13
0
        public void DeleteUserLogin(AspNetUserLogin userLogin)
        {
            if (userLogin == null)
            {
                throw new ArgumentNullException(nameof(userLogin));
            }

            var effectedRows = _userLoginRepository.DeleteRange(p => p.LoginProvider == userLogin.LoginProvider && p.ProviderKey == userLogin.ProviderKey);

            _cacheManager.Remove(string.Format(CachingKey.CommonMembershipUserServiceUserLoginByUserId, userLogin.UserId));
            _cacheManager.Remove(string.Format(CachingKey.CommonMembershipUserServiceUserLoginByProviderKeyAndLoginProvider, userLogin.ProviderKey, userLogin.LoginProvider));
        }
示例#14
0
 public void Update(AspNetUserLogin entity)
 {
     try
     {
         this.repository.Update(entity);
         return;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#15
0
 public void Update(AspNetUserLogin entity)
 {
     try
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#16
0
 public AspNetUserLogin GetById(int id)
 {
     try
     {
         AspNetUserLogin result = null;
         result = context.AspNetUserLogins.Find(id);
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#17
0
 public void Delete(AspNetUserLogin entity)
 {
     try
     {
         context.AspNetUserLogins.Remove(entity);
         context.Entry(entity).State = EntityState.Deleted;
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#18
0
        // GET: AspNetUserLogins/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetUserLogin aspNetUserLogin = db.AspNetUserLogins.Find(id);

            if (aspNetUserLogin == null)
            {
                return(HttpNotFound());
            }
            return(View(aspNetUserLogin));
        }
示例#19
0
 public int AddLogin(AspNetUserLogin AspNetUserLogin)
 {
     //helpaContext .Add<Author>(author);
     //context.SaveChanges();
     try
     {
         helpaContext.AspNetUserLogins.Add(AspNetUserLogin);
         helpaContext.SaveChanges();
         return(1);
     }
     catch (Exception e)
     {
         throw;
     }
 }
示例#20
0
        // GET: Dashboard/AdminUserLogin/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetUserLogin aspNetUserLogin = db.AspNetUserLogins.Find(id);

            if (aspNetUserLogin == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", aspNetUserLogin.UserId);
            return(View(aspNetUserLogin));
        }
示例#21
0
        public AspNetUserLogin InsertUserLogin(AspNetUserLogin userLogin)
        {
            if (userLogin == null)
            {
                throw new ArgumentNullException(nameof(userLogin));
            }

            _userLoginRepository.Insert(userLogin);
            _userLoginRepository.SaveChanges();

            _cacheManager.Remove(string.Format(CachingKey.CommonMembershipUserServiceUserLoginByUserId, userLogin.UserId));
            _cacheManager.Remove(string.Format(CachingKey.CommonMembershipUserServiceUserLoginByProviderKeyAndLoginProvider, userLogin.ProviderKey, userLogin.LoginProvider));

            return(userLogin);
        }
示例#22
0
        public ActionResult Login(AspNetUserLogin p)
        {
            using (bookdoctorEntities3 db = new bookdoctorEntities3())
            {
                var usr = db.AspNetUserLogins.SingleOrDefault((u => u.Email == p.Email));

                if (usr != null)
                {
                    if (usr.password.ToString() == p.password.ToString())
                    {
                        Session["Email"] = usr.Email.ToString();
                        return(RedirectToAction("DoctorWelcome"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Email or password is wrong or maybe you are not registered");
                }
            }
            return(View(p));
        }
示例#23
0
        public Task AddLoginAsync(AspNetUser user, UserLoginInfo login)
        {
            this.ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (login == null)
            {
                throw new ArgumentNullException("login");
            }

            AspNetUserLogin identityUserLogin = new AspNetUserLogin();

            identityUserLogin.AspNetUser    = user;
            identityUserLogin.ProviderKey   = login.ProviderKey;
            identityUserLogin.LoginProvider = login.LoginProvider;
            this.Context.Add(identityUserLogin);

            return(Task.FromResult <int>(0));
        }
        /// <summary>
        /// Create an external login if a registered user decide to use a social media to log in
        /// </summary>
        /// <param name="Info"></param>
        /// <returns></returns>
        public bool CreateExternalLogin(ExternalSignUpInformation Info)
        {
            bool result = false;

            try
            {
                AspNetUser aspNetUser = _aspNetUserRepo.FindAllBy(a => a.UserName == Info.Email).FirstOrDefault();
                if (aspNetUser != null)
                {
                    AspNetUserLogin login = new AspNetUserLogin();
                    login.LoginProvider = Info.LoginProvider;
                    login.ProviderKey   = Info.ProviderKey;
                    login.UserId        = aspNetUser.Id;
                    _aspNetUserLoginRepo.Add(login);
                    result = _aspNetUserLoginRepo.Save();
                }
            }
            catch (Exception e)
            {
                result = false;
                Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Email = " + Info.Email);
            }
            return(result);
        }
示例#25
0
        public async Task <IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            int userId = 0;

            if (!ModelState.IsValid)
            {
                string message = "";
                var    errors  = ModelState.Values;
                foreach (var err in errors)
                {
                    message = message + err.Errors[0].ErrorMessage;
                }

                return(BadRequest(message));
            }
            var usercheckExist = UserManager.FindByEmail(model.Email);

            if (usercheckExist == null)
            {
                var usercheckusername = UserManager.FindByName(model.UserName);
                if (usercheckusername == null)
                {
                    //var usercheckPhoneNo = helperServices.GetAllUsers().Where(x => x.PhoneNumber == model.PhoneNumber).FirstOrDefault();
                    //if (usercheckPhoneNo == null)
                    //{
                    var user = new ApplicationUser()
                    {
                        UserName = model.UserName, Email = model.Email, RowStatus = true
                    };
                    IdentityResult result = await UserManager.CreateAsync(user);

                    var IdCreated = new CreatedId();
                    if (result.Succeeded)
                    {
                        var lastAddedUser = await UserManager.FindByNameAsync(user.UserName);

                        userId = lastAddedUser.Id;
                        await UserManager.AddToRoleAsync(userId, model.Role);

                        IdCreated.Id = userId;
                        int UserId    = helperServices.GetAllUsers().OrderByDescending(x => x.Id).FirstOrDefault().Id;
                        var UserLogin = new CustomUserLogin()
                        {
                            UserId = UserId, ProviderKey = model.LoginProvider
                        };

                        AspNetUserLogin UserData = new AspNetUserLogin();
                        UserData.LoginProvider = model.LoginProvider;
                        UserData.UserId        = UserLogin.UserId;

                        UserData.ProviderKey = model.Token.Substring(0, 120);
                        int Id = helperServices.AddLogin(UserData);
                        //return Ok(new { Code = "200", Message = "Success", Data = userId });
                    }


                    return(Ok(new { Code = "200", Message = "Success", Data = IdCreated.Id }));
                }
                //    return BadRequest("Phone No Already Exit");
                //}
                string Messge = "User Name Already Exit";
                return(BadRequest(Messge));
            }
            return(BadRequest("Email Already Exit"));
        }
示例#26
0
 public bool UnlockUserLogin(AspNetUserLogin vUserLogin)
 {
     throw new NotImplementedException();
 }