public UserResObj validateUser(string email, string token, string pushID) { UserResObj userLogin = new UserResObj(); userLogin.response = new BaseResponse(); try { var db = _db; var temp = db.User.Where(u => u.Email.Equals(email) && u.TokenActivate.Equals(token)); if (temp.Count() > 0) { if (string.IsNullOrEmpty(pushID)) { pushID = "pushID"; } var userObj = temp.SingleOrDefault(); userObj.EmailVerified = 1; userObj.UserStatus = Constant.USER_ACTIVE; userObj.PushId = pushID; db.SaveChanges(); userLogin.response.status = 1; userLogin.response.developerMessage = "Verification Successfull"; userLogin.fillObject(userObj); } else { userLogin.response.status = -1; userLogin.response.developerMessage = "Invalid Pin"; } } catch (Exception e) { userLogin.response.status = -1; userLogin.response.developerMessage = "Something went wrong: " + e.Message; } return(userLogin); }
public UserResObj loginUser(string email, string password, string pushID) { UserResObj userLogin = new UserResObj(); userLogin.response = new BaseResponse(); string encryptedPassword = Utils.CreateMD5(password); try { var db = _db; var temp = db.User.Where(u => u.Email.Equals(email) && u.Password.Equals(encryptedPassword)) .FirstOrDefault(); if (temp != null) { var user = temp; if (user.UserStatus == Constant.USER_INACTIVE) { userLogin.response.status = 3; userLogin.response.developerMessage = "Account Inactive"; return(userLogin); } int isEmailVerified = (int)user.EmailVerified; if (isEmailVerified == 1) { if (string.IsNullOrEmpty(pushID)) { pushID = "pushID"; } user.PushId = pushID; db.SaveChanges(); userLogin.response.status = 1; userLogin.response.developerMessage = "Login Successfull"; userLogin.fillObject(user); return(userLogin); } else { string subject = Application.Constant.INSERT_USER_EMAIL_SUBJECT; string body = Application.Constant.INSERT_USER_EMAIL_BODY + temp.TokenActivate; Application.Utils.sendEmail(subject, body, temp.Email); userLogin.response.status = 2; userLogin.response.developerMessage = "Email not verified."; return(userLogin); } } userLogin.response.status = -1; userLogin.response.developerMessage = "Incorrect Credentials"; return(userLogin); } catch (Exception e) { userLogin.response.status = 0; userLogin.response.developerMessage = "Something Went Wrong: " + e.Message; return(userLogin); } }