public static void SaveProfile(LMCookieJS cook) { var db = Lib.CreateContext(); var usr = db.Users.First(u => u.Id == cook.id); cookie2user(cook, usr); Lib.SaveChanges(db); }
static void cookie2user(LMCookieJS cook, Users usr) { var el = new El(cook.EMail, cook.Login); usr.EMail = el.email; usr.FirstName = cook.FirstName; usr.LastName = cook.LastName; usr.Login = el.login; usr.LoginEMail = cook.LoginEMail; usr.OtherType = (short)cook.Type; usr.OtherId = cook.TypeId; usr.OtherData = cook.OtherData; }
public static Int64 CreateLmUserStart(LMCookieJS cook, string psw) { var db = Lib.CreateContext(); var el = new El(cook.EMail, cook.Login); psw = LowUtils.unpackStr(psw); var usr = db.Users.FirstOrDefault(u => u.EMail == el.email && u.Login == el.login); if (usr != null) switch ((VerifyStates)usr.VerifyStatus) { case VerifyStates.ok: if (usr.OtherType == (short)OtherType.LANGMaster || usr.OtherType == (short)OtherType.LANGMasterNoEMail) return -1; //user already registered else { //zmena z FB, Google apod. login na LM login usr.Password = psw; usr.OtherType = (short)OtherType.LANGMaster; usr.OtherId = null; usr.FirstName = cook.FirstName; usr.LastName = cook.LastName; Lib.SaveChanges(db); return usr.Id; } case VerifyStates.waiting: return usr.Id; case VerifyStates.prepared: usr.Password = psw; usr.VerifyStatus = (short)VerifyStates.waiting; Lib.SaveChanges(db); return usr.Id; } if (usr == null) db.Users.Add(usr = new Users() { Created = DateTime.UtcNow, VerifyStatus = cook.Type == OtherType.LANGMasterNoEMail ? (short)VerifyStates.ok : (short)VerifyStates.waiting, Password = psw, }); if (el.email == masterEMail) { usr.Roles = (Int64)Role.Admin; usr.VerifyStatus = (short)VerifyStates.ok; } cookie2user(cook, usr); Lib.SaveChanges(db); return usr.Id; } const string masterEMail = "*****@*****.**";